Skip to content

IdToken

nov edited this page May 16, 2020 · 10 revisions

AppleID::IdToken

ID Token Claims

id_token = token_response.id_token

id_token.iss # => "https://appleid.apple.com"
id_token.aud # => Your Client ID
id_token.sub # => Apple User Identifier (a.k.a. Subject Identifier)
id_token.iat # => issued_at (Unix Timestamp)
id_token.exp # => expires_at (Unix Timestamp)
id_token.at_hash # => hash value of access_token which is issued together with the id_token

id_token.original_jwt # => JSON::JWS (in case of you need direct JWT access)

ID Token Decoding

When getting ID Token via AppleID::Client#access_token!, received id_token is automatically decoded.

However, if you manually decode id_token, use this method.

AppleID::IdToken.decode 'eyJ..'

ID Token Verification

When obtained via back-channel TLS communication

In this case, you don't have to verify id_token signature nor ac_hash.

id_token.verify!(
  client: client,
  verify_signature: false
)

Moreover, you can just skip all verification step.

However, if you do full verification, do as below.

id_token.verify!(
  client: client,
  nonce: session[:nonce],
  access_token: token_response.access_token, # NOTE: Check at_hash
  # verify_signature: true # NOTE: this is the default
)

NOTE: JWKS caching feature will reduce unnecessary JWKS fetch requests for signature verification.

Otherwise

Probably you don't need this gem, or you need to get id_token via back-channel TLS communication

Clone this wiki locally