Assent.Strategy.Apple (Assent v0.4.0)

Copy Markdown View Source

Apple Sign In OpenID Connect strategy.

You'll need to collect the 10-char long Team ID, the Services ID, the 10-char Key ID and download the private key from the portal. Save the private key to an accessible folder, or alternatively set :private_key with the content of the private key.

Usage

config = [
  client_id: "REPLACE_WITH_SERVICES_ID",
  team_id: "REPLACE_WITH_TEAM_ID",
  private_key_id: "REPLACE_WITH_PRIVATE_KEY_ID",
  private_key_path: "/path/to/private_key.p8",
  redirect_uri: "http://localhost:4000/auth/callback"
]

With JS SDK

You can use the JS SDK instead of handling it through authorize_url/1. All you have to do is to set up your HTML page in the following way:

<html>
  <head>
      <meta name="appleid-signin-client-id" content="[CLIENT_ID]">
      <meta name="appleid-signin-scope" content="[SCOPES]">
      <meta name="appleid-signin-redirect-uri" content="[REDIRECT_URI]">
      <meta name="appleid-signin-state" content="[STATE]">
  </head>
  <body>
      <div id="appleid-signin" data-color="black" data-border="true" data-type="sign in"></div>
      <script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
  </body>
</html>

You can get the state by generating the session params using the authorize_url/1:

{:ok, %{session_params: session_params}} = Assent.Strategy.Apple.authorize_url(config)

Use the session_params[:state] value for [STATE]. The callback phase would be identical to how it's explained in the Assent docs.

See the Sign in with Apple JS documentation for more.

User info

The user info may include these claims specific to Apple:

  • is_private_email - indicates whether the email that the user shares is a proxy address;
  • real_user_status - indicates whether the user appears to be a real person;
  • org_id - indicates the organization ID associated with the user;

Names

For privacy, Apple doesn't include the user's name in the ID token. Instead, the browser submits it in a user parameter during initial authorization. This data is unverified and can be modified by the end user. If you want to include the name in the user info, add this to the config:

include_unverified_name: true

Once enabled and if available in the user parameter, given_name and family_name fields will be included in the user info.

Summary

Functions

Generates an OpenID Connect authorization URL.

Fetches user data from an ID Token or the UserInfo endpoint.

Returns user claims without provider-specific normalization.

Functions

authorize_url(config)

@spec authorize_url(Keyword.t()) :: Assent.Strategy.OIDC.on_authorize_url()

Generates an OpenID Connect authorization URL.

fetch_user(config, token)

@spec fetch_user(Keyword.t(), map()) :: {:ok, map()} | {:error, term()}

Fetches user data from an ID Token or the UserInfo endpoint.

normalize(config, user)

Returns user claims without provider-specific normalization.