Class AppleSignIn

java.lang.Object
com.codename1.social.Login
com.codename1.social.AppleSignIn

public final class AppleSignIn extends Login

Sign in with Apple for Codename One. Replaces the external cn1-applesignin library for new code; the cn1lib continues to work on its own (this class doesn't depend on it and doesn't forward to it -- they're independent implementations).

Behavior by platform:

  • iOS 13+ -- native ASAuthorizationAppleIDProvider flow via AppleSignInNative. Returns the identity token plus the user's name and email on the first authorization (Apple does not echo them on subsequent ones; this class persists them in Preferences).
  • Android / JavaSE / Web -- web fallback via OidcClient against the public Apple OIDC issuer (https://appleid.apple.com). Requires a Services ID (web client ID), a redirect URI registered with Apple, and a client_secret JWT generated server-side (use Login.setClientSecret(String)).
Quick example
AppleSignIn apple = AppleSignIn.getInstance()
    .withServiceId("com.example.appleweb")     // web only
    .withRedirectUri("https://example.com/cb"); // web only

apple.signIn("name email", new AppleSignInCallback() {
    public void onSuccess(AppleSignInResult result) {
        String id    = result.getUserId();
        String email = result.getEmail();
        String idTok = result.getIdentityToken();
        // send idTok to your backend for verification
    }
    public void onError(String error) { ... }
    public void onCancel() { ... }
});
Since:
7.0.245
  • Field Details

  • Method Details

    • getInstance

      public static AppleSignIn getInstance()
    • withServiceId

      public AppleSignIn withServiceId(String serviceId)
      Apple Services ID used for the web fallback. Required only when running on platforms without the native sheet (Android, JavaSE, Web).
    • withRedirectUri

      public AppleSignIn withRedirectUri(String redirectUri)
      Redirect URI registered with Apple for the Services ID. Used by the web fallback.
    • withClientSecret

      public AppleSignIn withClientSecret(String secret)
      Client-secret JWT generated by your backend (Apple does not let mobile apps mint this themselves -- see the developer guide for the recipe).
    • withDefaultScopes

      public AppleSignIn withDefaultScopes(String scopes)
    • isNativeLoginSupported

      public boolean isNativeLoginSupported()
      Description copied from class: Login

      Returns true if this service supports native login. If implementation returns true here, the nativelogin, nativelogout, nativeIsLoggedIn should be implemented

      Returns

      true if the service supports native login

      Specified by:
      isNativeLoginSupported in class Login
    • nativeIsLoggedIn

      public boolean nativeIsLoggedIn()
      Description copied from class: Login

      Indicates if the user is currently logged in. Subclasses that uses a native sdk to login/logout should override this method.

      Returns

      true if logged in

      Overrides:
      nativeIsLoggedIn in class Login
    • nativeLogout

      public void nativeLogout()
      Description copied from class: Login
      Logs out the current user natively. Subclasses that uses a native sdk to login/logout should override this method.
      Overrides:
      nativeLogout in class Login
    • nativelogin

      public void nativelogin()
      Description copied from class: Login
      Logs in the current user natively. Subclasses that uses a native sdk to login/logout should override this method.
      Overrides:
      nativelogin in class Login
    • validateToken

      protected boolean validateToken(String token)
      Description copied from class: Login

      Returns true if the previous granted access token is still valid otherwise false.

      Parameters
      • token: the access token to check
      Returns

      true of the token is valid

      Specified by:
      validateToken in class Login
    • signIn

      public void signIn(String scopes, AppleSignInCallback callback)
      Primary entry point. Triggers either the native sheet (iOS) or the web OIDC fallback (everything else) and delivers the result to callback.
    • setProvider

      public static void setProvider(AppleSignInNative p)

      Registers the native AppleSignInNative implementation. Called at app startup by the port (AppleSignInNativeImpl.init()); cn1lib authors can also call this to plug in their own implementation, e.g. wrapping the AuthenticationServices framework differently. Pass null to fall back to the OidcClient web flow.

      We use an explicit setter rather than Class.forName because Codename One obfuscates class names; the port instantiates the impl itself and passes the instance here.