All Projects → marpies → account-kit-ane

marpies / account-kit-ane

Licence: Apache-2.0 license
AccountKit extension for Adobe AIR (iOS & Android)

Programming Languages

objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language
actionscript
884 projects
c
50402 projects - #5 most used programming language

Account Kit | Native extension for Adobe AIR (iOS & Android)

Account Kit helps people quickly and easily register and log into your app using their phone number or email address as a passwordless credential. Account Kit is powered by Facebook's email and SMS sending infrastructure for reliable scalable performance with global reach. Using email and phone number authentication doesn't require a Facebook account, and is the ideal alternative to a social login.

Development of this extension is supported by Master Tigra, Inc.

Native SDK versions

  • iOS v4.20.0
  • Android v4.20.0

Features

  • User-friendly login via email or SMS
  • Storing custom user preferences
  • Retrieving AccountKit account data

Getting started

Start by creating a Facebook app in the Facebook developer dashboard. Next, add AccountKit product from the dashboard menu on the left. Write down your Facebook app ID and AccountKit client token.

Modify Android resources

(skip this step if you target iOS only)

AccountKit SDK for Android requires Android resources which contain your Facebook app ID and AccountKit client token. These resources are part of the extension package and must be specified when building APK file, thus you will need to repackage the extension with resources that hold your information. If you do not intend to target Android platform then use the extension package from the bin directory and skip over to Additions to AIR descriptor section. To modify the resources, open the file strings.xml and replace the placeholders with actual values from the developer dashboard:

  • {FACEBOOK_APP_ID} with your Facebook app ID
  • {ACCOUNT_KIT_CLIENT_TOKEN} with your AccountKit client token

Update build.properties variables air.sdk and gradle.exec to point to AIR SDK 23+ root directory and to Gradle executable. Navigate to the build directory from the command line and run ant all to build and package the extension.

Modify AIR SDK library

(skip this step if you target iOS only or using AIR 27+)

The AccountKit SDK for Android uses AppCompat resources for styling UI activities presented to the user. AIR SDK uses older version of these resources which must be removed from the AIR SDK to avoid conflict with newer version. Since the following steps directly modify the SDK, I suggest you create a copy of the SDK directory, mark it as patched and only use it for apps where AccountKit ANE is included.

  1. Download adt.jar for your AIR SDK version from the air_sdk_patch directory. Copy and paste it to AIR_SDK_patched/lib, replacing the existing file.
  2. (Skip this step if using AIR 25+) Download runtimeClasses.jar for your AIR SDK version from the air_sdk_patch directory. Copy and paste it to AIR_SDK_patched/lib/android/lib, replacing the existing file.

Additions to AIR descriptor

Add the extension's ID to the extensions element.

<extensions>
    <extensionID>com.marpies.ane.facebook.accountkit</extensionID>
</extensions>

If you are targeting Android, add the following extensions from this repository as well (unless you know these libraries are included by some other extensions):

<extensions>
    <extensionID>com.marpies.ane.androidsupport</extensionID>
    <extensionID>com.marpies.ane.androidsupport.appcompat</extensionID>
    <extensionID>com.marpies.ane.androidsupport.design</extensionID>
    <extensionID>com.marpies.ane.androidsupport.recyclerview</extensionID>
    <extensionID>com.marpies.ane.androidsupport.vectordrawable</extensionID>
    <extensionID>com.marpies.ane.androidsupport.animatedvectordrawable</extensionID>
</extensions>

For iOS support, look for the iPhone element and make sure it contains the following InfoAdditions:

<iPhone>
    <InfoAdditions>
        <![CDATA[
        <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleURLSchemes</key>
                    <array>
                        <string>ak{FACEBOOK_APP_ID}</string>
                    </array>
            </dict>
        </array>

        <key>AccountKitClientToken</key>
        <string>{ACCOUNT_KIT_CLIENT_TOKEN}</string>

        <key>MinimumOSVersion</key>
        <string>7.0</string>
        ]]>
    </InfoAdditions>

    ...
</iPhone>

In the snippet above, replace:

  • {FACEBOOK_APP_ID} with your Facebook app ID
  • {ACCOUNT_KIT_CLIENT_TOKEN} with your AccountKit client token

For Android support, modify manifestAdditions element so that it contains the following meta-data and activities. Note the meta-data com.facebook.accountkit.FacebookAppEventsEnabled requires Facebook SDK to be included in your app; alternatively you can set the value to false to disable event logging made by AccountKit SDK.

<android>
    <manifestAdditions>
        <![CDATA[
        <manifest android:installLocation="auto">

            <uses-permission android:name="android.permission.INTERNET"/>

            <!-- OPTIONAL: allows the SDK to pre-fill user email and phone number when launching login activity -->
            <uses-permission android:name="android.permission.RECEIVE_SMS" />
            <uses-permission android:name="android.permission.READ_PHONE_STATE" />
            <uses-permission android:name="android.permission.GET_ACCOUNTS" />

            <application>

                <!-- AccountKit BEGIN -->
                <meta-data android:name="com.facebook.accountkit.ApplicationName" android:value="@string/app_name" />
                <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/FACEBOOK_APP_ID" />
                <meta-data android:name="com.facebook.accountkit.ClientToken" android:value="@string/ACCOUNT_KIT_CLIENT_TOKEN" />
                <!-- Optional event logging -->
                <meta-data android:name="com.facebook.accountkit.FacebookAppEventsEnabled" android:value="true" />

                <activity
                    android:name="com.facebook.accountkit.ui.AccountKitActivity"
                    android:label="@string/com_accountkit_button_log_in"
                    android:launchMode="singleTop"
                    android:theme="@style/Theme.AccountKit"
                    android:windowSoftInputMode="adjustResize">
                    <intent-filter>
                        <action android:name="android.intent.action.VIEW" />
                        <category android:name="android.intent.category.DEFAULT" />
                        <category android:name="android.intent.category.BROWSABLE" />
                        <data android:scheme="@string/ak_login_protocol_scheme" />
                    </intent-filter>
                </activity>
                <activity
                    android:name="com.facebook.accountkit.ui.AccountKitEmailRedirectActivity"
                    android:exported="true"
                    android:noHistory="true" />
                <!-- AccountKit END -->

            </application>

        </manifest>
        ]]>
    </manifestAdditions>
</android>

Finally, add the AccountKit ANE or SWC package from the bin directory to your project so that your IDE can work with it. The additional Android library ANEs are only necessary during packaging.

API overview

Initialization

Initialize the extension using the init method that accepts the following parameters:

  • loginType - determines whether you app receives access token or authorization code only, see AKResponseType class
  • initCallback - function that will be called when the SDK is initialized
  • showLogs - set to true to enable extension logs
AccountKit.init( AKResponseType.ACCESS_TOKEN, onAccountKitInitialized, true );

private function onAccountKitInitialized():void {
    trace( "AccountKit SDK initialized" );
}

Once the SDK is initialized, you can see if there is a user currently logged in by checking the access token:

var token:AKAccessToken = AccountKit.accessToken;
if( token != null ) {
    trace( "AccountKit user is logged in: " + token.accountId );
    trace( "Last refresh: " + token.lastRefresh );
}

Login

You can initiate user login by calling the login method along with a configuration object:

var config:AKConfiguration = new AKConfiguration();
config.loginType = AKLoginType.EMAIL; // or AKLoginType.PHONE to login via SMS
config.initialAuthState = "random-nonce";
config.initialEmail = "[email protected]"; // prefill user's email manually
config.setInitialPhoneNumber( "US", "1234567890"); // prefill user's phone number manually
// Values below apply to Android only
config.defaultCountryCode = "US"; // default country code shown in the SMS login flow
config.enableFacebookNotification = true; // receive confirmation via Facebook notification
config.titleType = AKTitleType.APP_NAME; // or AKTitleType.LOGIN
config.enableReadPhoneState = true; // prefill user's phone number automatically
config.receiveSms = true; // prefill confirmation code automatically
config.smsWhiteList = new <String>["US", "NL"]; // list of allowed country codes for SMS
config.smsBlackList = new <String>["UK"]; // list of excluded country codes for SMS

...

AccountKit.login( config, onAccountKitLoginResult );

private function onAccountKitLoginResult( result:AKLoginResult ):void {
    trace( "AccountKit login result" );
    if( result.wasCancelled ) {
        trace( "> was cancelled" );
    } else if( result.errorMessage != null ) {
        trace( "> failed: " + result.errorMessage );
    } else {
        trace( "> is success | auth state: " + result.authorizationState ); // check to match 'config.initialAuthState'
        // either accessToken or authorizationCode will be set depending on the AKResponseType used when initializing the extension
        trace( "> accessToken: " + result.accessToken );
        trace( "> authorizationCode: " + result.authorizationCode );
    }
}

Account details

To retrieve details about current account, call:

AccountKit.getCurrentAccount( onAccountKitAccountRetrieved );

private function onAccountKitAccountRetrieved( account:AKAccount, errorMessage:String ):void {
    if( errorMessage != null ) {
        trace( "Error getting account info: " + errorMessage );
    } else {
        trace( "Account id: " + account.id );
        trace( "Account email: " + account.email );
        trace( "Account phoneNumber: " + account.phoneNumber );
        trace( "Account phoneNumberCountryCode: " + account.phoneNumberCountryCode );
    }
}

User preferences

You may store up to 100 key/value pairs per user. A key is a string of up to 100 characters; allowed characters are uppercase and lowercase letters, numerals, and the underscore. A value is a string of up to 1000 characters.

To interact with user preferences, get the AKAccountPreferences object using AccountKit.accountPreferences. To set a user preference, call:

AccountKit.accountPreferences.setPreference( "key", "value", onAccountKitPreferenceSet );

private function onAccountKitPreferenceSet( key:String, value:String, errorMessage:String ):void {
    if( errorMessage != null ) {
        trace( "Error setting pref: " + errorMessage );
    } else {
        trace( "Set pref: " + key + " -> " + value );
    }
}

To load a preference, call:

AccountKit.accountPreferences.loadPreference( "key", onAccountKitPreferenceLoaded );

private function onAccountKitPreferenceLoaded( key:String, value:String, errorMessage:String ):void {
    if( errorMessage != null ) {
        trace( "Error loading pref: " + errorMessage );
    } else {
        trace( "Loaded pref: " + key + " -> " + value );
    }
}

To delete a preference, call:

AccountKit.accountPreferences.deletePreference( "key", onAccountKitPreferenceDeleted );

private function onAccountKitPreferenceDeleted( key:String, errorMessage:String ):void {
    if( errorMessage != null ) {
        trace( "Error deleting pref: " + errorMessage );
    } else {
        trace( "Deleted pref: " + key );
    }
}

To load all preferences, call:

AccountKit.accountPreferences.loadPreferences( onAccountKitPreferencesLoaded );

private function onAccountKitPreferencesLoaded( preferences:Object, errorMessage:String ):void {
    if( errorMessage != null ) {
        trace( "Error loading pref: " + errorMessage );
    } else {
        trace( "Loaded all preferences:" );
        for( var key:String in preferences ) {
            trace( "Preference", key, "has value", preferences[key] );
        }
    }
}

Requirements

  • iOS 7+
  • Android 4+
  • Adobe AIR 23+

Documentation

Generated ActionScript documentation is available in the docs directory, or can be generated by running ant asdoc from the build directory.

Build ANE

ANT build scripts are available in the build directory. Edit build.properties to correspond with your local setup.

Author

The ANE has been developed by Marcel Piestansky and is distributed under Apache License, version 2.0.

Changelog

March 26, 2017 (v1.3.0)

  • UPDATED AccountKit SDKs to v4.20.0 for both iOS and Android

December 16, 2016 (v1.2.0)

  • ADDED compatibility with AIR SDK 24 (AIR SDK 23 is now the min required version)

November 29, 2016 (v1.1.0)

  • UPDATED AccountKit SDKs to v4.17.0 for both iOS and Android
  • FIXED iOS login callback for AKLoginType.PHONE

September 16, 2016 (v1.0.1)

  • ADDED support for Android 4.x

September 14, 2016 (v1.0.0)

  • Public release
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].