← All extensions

Native extension

KlugAuth

com.klug.auth.KlugAuth

Sign in with Apple and Sign in with Google from ActionScript, with the system sign-in sheets. Your app receives a verified identity token for your server, so users create an account without inventing a password.

iOSAndroidmacOSiPad on Mac In development

Overview

Most users give up at the registration form: a username, a password they have to remember, an e-mail code that lands in spam. With KlugAuth they tap Continue with Apple or Continue with Google and are done.

KlugAuth shows the native sign-in of each platform: Apple's sheet with Face ID / Touch ID on iOS and macOS, the Android account sheet (Credential Manager) for Google, and the system sign-in window for Google on iOS and macOS. It returns the provider's identity token together with your nonce, ready for verification on your server, plus the Apple authorization code you need to revoke the link when an account is deleted (App Store guideline 5.1.1(v)).

No Google SDK is bundled: Google sign-in on iOS and macOS uses the standard OAuth flow with PKCE in the system browser sheet, so the extension stays small.

KlugAuth runs in the next release of the PetCam App, our proof of concept, for registration, sign-in and confirming a pet-station logout with Apple or Google.

Features

  • Sign in with Apple on iOS 13+, macOS 10.15+ and iPad apps on Apple silicon Macs
  • Sign in with Google on Android (Credential Manager) and on iOS / macOS (system sign-in window, no Google SDK)
  • Identity token, user ID, e-mail and name; Apple authorization code for refresh and revocation
  • Nonce helper for replay protection (Apple carries its SHA-256, Google the raw value)
  • Apple credential state check (authorized / revoked) for returning users
  • Separate success, cancel and error events; cancel is reported, never an error

Supported platforms

iOS Apple + Google · arm64
Android Google · Credential Manager
macOS Apple + Google · arm64 · x86_64
iPad on Mac Apple + Google

Sign in with Apple on Android is possible with Apple's web flow and a small server page; we can provide that as part of a project. isSupported (Apple) and isGoogleSupported tell your code what the device offers.

Getting started

Add the extension to your application descriptor:

app.xml
<extensions>
    <extensionID>com.klug.auth.KlugAuth</extensionID>
</extensions>

For Sign in with Apple, add the entitlement (iOS: Entitlements in the descriptor; macOS: when signing):

app.xml · Entitlements
<key>com.apple.developer.applesignin</key>
<array><string>Default</string></array>

For Google, create OAuth clients in the Google Cloud console: a web client (its ID is the token audience on Android), an Android client with your package name and SHA-1, and an iOS client for iOS and macOS.

Quick example

SignIn.as
import com.klug.auth.KlugAuth;
import com.klug.auth.KlugAuthEvent;

var auth:KlugAuth = KlugAuth.getInstance();
var nonce:String = KlugAuth.generateNonce();

auth.addEventListener( KlugAuthEvent.APPLE_SUCCESS, function( e:KlugAuthEvent ):void {
    sendToServer( "apple", e.identityToken, nonce, e.authorizationCode );   // verify the token on your server
});
auth.addEventListener( KlugAuthEvent.GOOGLE_SUCCESS, function( e:KlugAuthEvent ):void {
    sendToServer( "google", e.identityToken, nonce );
});
auth.addEventListener( KlugAuthEvent.APPLE_CANCELED, onCanceled );
auth.addEventListener( KlugAuthEvent.GOOGLE_ERROR, onError );   // e.errorCode / e.errorMessage

if ( auth.isSupported ) auth.signInWithApple( nonce );
else auth.signInWithGoogle( GOOGLE_CLIENT_ID, nonce );

API overview

KlugAuth.getInstance()Returns the single instance.
isSupportedTrue where Sign in with Apple is available (iOS, macOS).
isGoogleSupportedTrue where Sign in with Google is available (Android, iOS, macOS).
generateNonce()A fresh random nonce; send the same value to your server.
signInWithApple(nonce)Opens Apple's sign-in sheet.
signInWithGoogle(clientId, nonce)Opens Google sign-in. Android: the web client ID; iOS / macOS: the iOS client ID.
getCredentialState(userID)Asks Apple whether the user is still authorized (APPLE_CREDENTIAL_STATE).
KlugAuthEvent.APPLE_SUCCESS / GOOGLE_SUCCESSidentityToken, userID, email, fullName; Apple also authorizationCode.
…_CANCELED / …_ERRORThe user closed the sheet / errorCode and errorMessage.

Requirements

AIR SDK51.x (HARMAN)
iOSiOS 13 or later
AndroidAndroid 6 or later, Google Play services
macOSmacOS 10.15 or later
AppleSign in with Apple capability on your App ID
GoogleOAuth clients in the Google Cloud console