Class AppleClientSecretGenerator

java.lang.Object
com.irurueta.authserver.authorization.api.web.social.AppleClientSecretGenerator

public final class AppleClientSecretGenerator extends Object
Generates the client secret Sign in with Apple requires: a JWT signed with ES256 by the key Apple issued (iss the team id, sub the client id, aud https://appleid.apple.com, header kid the key id), valid for a short time. The token request of the framework asks for it each time, so the secret is cached and renewed when half of its lifetime has passed.

It does not use the JwtEncoder of the server's own signing keys: Apple verifies the secret with the key registered in its developer account, so only that key can sign it. It is a dedicated Nimbus signer over the Apple key supplied from the environment.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
    Audience Apple requires in the client secret.
    private final com.github.benmanes.caffeine.cache.Cache<String,String>
    Holds the current secret until it is half way through its life.
    private final String
    Client id registered with Apple (the services id).
    private final Clock
    Source of the current time.
    private final String
    Id of the key that signs the secret.
    private static final int
    The secret is renewed when this fraction of its lifetime has passed.
    private final com.nimbusds.jose.crypto.ECDSASigner
    Signs with the Apple key.
    private final String
    Apple developer team id.
    private final Duration
    Lifetime of a secret.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the generator.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the client id (the Services ID) the secrets are signed for, which is also the client_id of the token requests and of the authorization requests.
    Returns a client secret that is valid now.
    private String
    Signs a new secret.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • AUDIENCE

      static final String AUDIENCE
      Audience Apple requires in the client secret.
      See Also:
    • RENEWAL_DIVISOR

      private static final int RENEWAL_DIVISOR
      The secret is renewed when this fraction of its lifetime has passed.
      See Also:
    • clientId

      private final String clientId
      Client id registered with Apple (the services id).
    • teamId

      private final String teamId
      Apple developer team id.
    • keyId

      private final String keyId
      Id of the key that signs the secret.
    • ttl

      private final Duration ttl
      Lifetime of a secret.
    • clock

      private final Clock clock
      Source of the current time.
    • signer

      private final com.nimbusds.jose.crypto.ECDSASigner signer
      Signs with the Apple key.
    • cache

      private final com.github.benmanes.caffeine.cache.Cache<String,String> cache
      Holds the current secret until it is half way through its life.
  • Constructor Details

    • AppleClientSecretGenerator

      public AppleClientSecretGenerator(SocialProperties.Provider settings, ECPrivateKey key, Clock clock)
      Creates the generator.
      Parameters:
      settings - settings of the Apple provider.
      key - private key Apple issued.
      clock - source of the current time.
      Throws:
      IllegalArgumentException - if the key cannot sign with ES256.
  • Method Details

    • clientId

      public String clientId()
      Gets the client id (the Services ID) the secrets are signed for, which is also the client_id of the token requests and of the authorization requests.
      Returns:
      the client id.
    • generate

      public String generate()
      Returns a client secret that is valid now.
      Returns:
      the signed JWT.
    • sign

      private String sign()
      Signs a new secret.
      Returns:
      the serialized JWT.