public final class AppleSignIn

  1. Object
  2. Login
  3. AppleSignIn

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 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() { ... }
});

Fields

public static final String APPLE_ISSUER = "https://appleid.apple.com"Apple’s public OIDC issuer.

Methods

public static synchronized AppleSignIn getInstance()
public AppleSignIn withServiceId(String serviceId)Apple Services ID used for the web fallback.
public AppleSignIn withRedirectUri(String redirectUri)Redirect URI registered with Apple for the Services ID.
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).
public AppleSignIn withDefaultScopes(String scopes)
public boolean isNativeLoginSupported()Returns true if this service supports native login.
public boolean nativeIsLoggedIn()Indicates if the user is currently logged in.
public void nativeLogout()Logs out the current user natively.
public void nativelogin()Logs in the current user natively.
protected boolean validateToken(String token)Returns true if the previous granted access token is still valid otherwise false.
public void signIn(String scopes, AppleSignInCallback callback)Primary entry point.
public static void setProvider(AppleSignInNative p)Registers the native AppleSignInNative implementation.

Inherited methods

Field details

APPLE_ISSUER

public static final String APPLE_ISSUER = "https://appleid.apple.com"
Apple’s public OIDC issuer.

Method details

getInstance

public static synchronized 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()
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

nativeIsLoggedIn

public boolean nativeIsLoggedIn()
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

nativeLogout

public void nativeLogout()
Logs out the current user natively. Subclasses that uses a native sdk to login/logout should override this method.

nativelogin

public void nativelogin()
Logs in the current user natively. Subclasses that uses a native sdk to login/logout should override this method.

validateToken

protected boolean validateToken(String token)
Returns true if the previous granted access token is still valid otherwise false.

Parameters

token String
the access token to check

Returns

true of the token is valid

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.