Apple's Sign in with Apple is OIDC-compatible, so it works through Wekan's existing generic OAuth2/OIDC client - except its "client secret" is not a static string: it must be a short-lived JWT the server signs itself (ES256), using a private key downloaded from Apple's developer portal. Every other generic OAuth2 provider Wekan supports (Keycloak, Authelia, Nextcloud, ...) keeps sending its static OAUTH2_SECRET unchanged. models/lib/oauth2ClientSecretJwt.js mints that JWT using only Node's built-in crypto module (no new dependency: ES256 signing with IEEE-P1363 signature encoding has been supported since Node 12). It is opt-in: when OAUTH2_SECRET_JWT_KEY_PATH is unset (the default, and every existing provider's configuration), maybeGenerateOauth2ClientSecretJwt() returns null and packages/wekan-oidc/oidc_server.js falls back to the static OAUTH2_SECRET exactly as before. Apple's other quirk - it returns the user's name only on the very first authorization - needs no special-casing: Accounts.onCreateUser (server/models/users.js) already copies the OIDC fullname/email claims into the user's profile only once, at account creation, and never overwrites them on later logins (Meteor's updateOrCreateUserFromExternalService only touches services.oidc.* for a returning user, not profile.*). docs/Features/Login/Apple.md documents Apple's endpoints and the new env vars, mirroring the Keycloak/Authelia docs pattern. Thanks to xet7 ! Closes #2458,
5.6 KiB
Sign in with Apple using OAuth2/OIDC
- Original issue: https://github.com/wekan/wekan/issues/2458
- Apple: Configure Sign in with Apple for the web
- Apple: Generate and validate tokens
- Apple: Authenticating users with Sign in with Apple
Sign in with Apple exposes standard OpenID Connect endpoints, so it is configured as a Wekan generic OAuth2/OIDC provider like Keycloak or Authelia (see OAuth2.md). Its fixed, non-discoverable endpoints are:
authorization_endpoint:https://appleid.apple.com/auth/authorizetoken_endpoint:https://appleid.apple.com/auth/token
Apple has no public userinfo_endpoint; the user's identity is carried in the
id_token (a signed JWT) that the token endpoint returns, which Wekan already
reads: OAUTH2_USERINFO_ENDPOINT may be left unset, and
OAUTH2_ADFS_ENABLED=true (despite the name, this flag simply tells Wekan's
OIDC client "read claims from the access/id token instead of calling a
userinfo endpoint" - the same mechanism ADFS and Azure AD B2C use) makes Wekan
decode the claims (sub, email, email_verified, ...) straight out of the
token response instead of calling a userinfo endpoint.
Two things Apple does differently from every other Wekan OAuth2 provider
-
The client secret is not a static string - it is a JWT your server must sign. Every other provider documented under
docs/Features/Login/issues a plainOAUTH2_SECRETvalue that Wekan sends to the token endpoint as-is. Apple instead requires a compact JWT, signed with ES256, using a private key you download once from the Apple Developer portal (Keys → "Sign in with Apple" key), containing:iss: your Apple Team IDsub: your Services ID (the OAuth2client_id)aud:https://appleid.apple.comkid: the key's Key ID, andalg: ES256in the JWT headeriat/exp: issued-at and expiry (Apple allows up to ~6 months; Wekan mints a short-lived one fresh on every token-exchange request instead)
Wekan generates this JWT itself (
models/lib/oauth2ClientSecretJwt.js, using only Node's built-incryptomodule - no external dependency) whenOAUTH2_SECRET_JWT_KEY_PATHis set, and falls back to the plainOAUTH2_SECRETexactly as before when it is not. This is opt-in and changes nothing for Keycloak, Authelia, Nextcloud or any other provider that keeps using a staticOAUTH2_SECRET.Env var Required Meaning OAUTH2_SECRET_JWT_KEY_PATHto opt in Path to the .p8private key file downloaded from Apple (PEM/PKCS8 text). Setting this is what turns the feature on.OAUTH2_SECRET_JWT_ISSUERyes, once opted in Your Apple Team ID. OAUTH2_SECRET_JWT_KEY_IDyes, once opted in The Key ID ( kid) of the private key above.OAUTH2_SECRET_JWT_AUDIENCEno Defaults to https://appleid.apple.com.OAUTH2_SECRET_JWT_SUBJECTno Defaults to OAUTH2_CLIENT_ID(your Services ID).OAUTH2_SECRET_JWT_EXPIRES_INno Seconds until the minted JWT expires. Defaults to 300(5 minutes) - it only needs to outlive the single token-exchange request it is generated for.When
OAUTH2_SECRET_JWT_KEY_PATHis set,OAUTH2_SECRETitself is not used and may be left empty. -
Apple returns the user's name only on the very first authorization, never again on later logins - and only when your authorization request included
scope=name(and the user chose "Share My Email"/full name in Apple's consent dialog rather than "Hide My Email"). Nothing Apple-specific is needed for this in Wekan:Accounts.onCreateUser(server/models/users.js) copies the OIDCfullname/emailclaims into the Wekan user's ownprofile.fullname/emailsfields once, at account creation, and never overwrites them again on later logins (that hook only runs when the user document is first created - seeupdateOrCreateUserFromExternalServiceinaccounts-base, which on a returning user only touchesservices.oidc.*, notprofile.*). So the name captured on the first Apple sign-in is what Wekan keeps, even thoughservices.oidc.fullnameitself goes back to empty on every later login where Apple sends no name claim.
Docker
- OAUTH2_ENABLED=true
- OAUTH2_CLIENT_ID=<your Services ID>
- OAUTH2_SECRET_JWT_KEY_PATH=/path/to/AuthKey_XXXXXXXXXX.p8
- OAUTH2_SECRET_JWT_ISSUER=<your Apple Team ID>
- OAUTH2_SECRET_JWT_KEY_ID=<the key's Key ID>
- OAUTH2_SERVER_URL=https://appleid.apple.com
- OAUTH2_AUTH_ENDPOINT=/auth/authorize
- OAUTH2_TOKEN_ENDPOINT=/auth/token
- OAUTH2_ADFS_ENABLED=true
- OAUTH2_ID_MAP=sub
- OAUTH2_EMAIL_MAP=email
- OAUTH2_FULLNAME_MAP=name
- OAUTH2_REQUEST_PERMISSIONS=openid name email
Apple's authorization endpoint requires the request to use response_mode=form_post
whenever the name/email scopes are requested; if your Wekan instance needs
those on first login and the popup flow does not complete, try
OAUTH2_LOGIN_STYLE=redirect (see OAuth2.md).
Others
Similar like above Docker; set the equivalent environment variables/snap config keys for your platform, following OAuth2.md.