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 (useLogin.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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic AppleSignInbooleanReturns true if this service supports native login.booleanIndicates if the user is currently logged in.voidLogs in the current user natively.voidLogs out the current user natively.static voidRegisters the nativeAppleSignInNativeimplementation.voidsignIn(String scopes, AppleSignInCallback callback) Primary entry point.protected booleanvalidateToken(String token) Returns true if the previous granted access token is still valid otherwise false.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(String scopes) withRedirectUri(String redirectUri) Redirect URI registered with Apple for the Services ID.withServiceId(String serviceId) Apple Services ID used for the web fallback.Methods inherited from class Login
addScopes, connect, createOauth2, doLogin, doLogin, doLogout, getAccessToken, isPreferRedirectPrompt, isUserLoggedIn, setAccessToken, setCallback, setClientId, setClientSecret, setOauth2URL, setPreferRedirectPrompt, setRedirectURI, setScope, validateToken
-
Field Details
-
APPLE_ISSUER
-
-
Method Details
-
getInstance
-
withServiceId
Apple Services ID used for the web fallback. Required only when running on platforms without the native sheet (Android, JavaSE, Web). -
withRedirectUri
Redirect URI registered with Apple for the Services ID. Used by the web fallback. -
withClientSecret
Client-secret JWT generated by your backend (Apple does not let mobile apps mint this themselves -- see the developer guide for the recipe). -
withDefaultScopes
-
isNativeLoginSupported
public boolean isNativeLoginSupported()Description copied from class:LoginReturns 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:
isNativeLoginSupportedin classLogin
-
nativeIsLoggedIn
public boolean nativeIsLoggedIn()Description copied from class:LoginIndicates 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:
nativeIsLoggedInin classLogin
-
nativeLogout
public void nativeLogout()Description copied from class:LoginLogs out the current user natively. Subclasses that uses a native sdk to login/logout should override this method.- Overrides:
nativeLogoutin classLogin
-
nativelogin
public void nativelogin()Description copied from class:LoginLogs in the current user natively. Subclasses that uses a native sdk to login/logout should override this method.- Overrides:
nativeloginin classLogin
-
validateToken
Description copied from class:LoginReturns 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:
validateTokenin classLogin
-
signIn
Primary entry point. Triggers either the native sheet (iOS) or the web OIDC fallback (everything else) and delivers the result tocallback. -
setProvider
Registers the native
AppleSignInNativeimplementation. Called at app startup by the port (AppleSignInNativeImpl.init()); cn1lib authors can also call this to plug in their own implementation, e.g. wrapping theAuthenticationServicesframework differently. Passnullto fall back to theOidcClientweb flow.We use an explicit setter rather than
Class.forNamebecause Codename One obfuscates class names; the port instantiates the impl itself and passes the instance here.
-