Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class 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
ASAuthorizationAppleIDProviderflow viaAppleSignInNative. 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 inPreferences). - Android / JavaSE / Web – web fallback via
OidcClientagainst the public Apple OIDC issuer (https://appleid.apple.com). Requires a Services ID (web client ID), a redirect URI registered with Apple, and aclient_secretJWT generated server-side (usesetClientSecret(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
Inherited methods
Field details
APPLE_ISSUER
public static final String APPLE_ISSUER = "https://appleid.apple.com"Method details
getInstance
public static synchronized AppleSignIn getInstance()withServiceId
public AppleSignIn withServiceId(String serviceId)withRedirectUri
public AppleSignIn withRedirectUri(String redirectUri)withClientSecret
public AppleSignIn withClientSecret(String secret)withDefaultScopes
public AppleSignIn withDefaultScopes(String scopes)isNativeLoginSupported
public boolean isNativeLoginSupported()Returns
nativeIsLoggedIn
public boolean nativeIsLoggedIn()Returns
nativeLogout
public void nativeLogout()nativelogin
public void nativelogin()validateToken
protected boolean validateToken(String token)Parameters
tokenString- the access token to check
Returns
signIn
public void signIn(String scopes, AppleSignInCallback callback)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.