This project is a sample game developed in Unity to showcase how to integrate the Login with Amazon SDK in an Android app. The game is designed to work on Fire OS, Android, and Windows System for Android devices. ๐
-
Clone the repository:
git clone https://github.com/AmazonAppDev/login-with-amazon-unity-sample
-
Open the project in Unity.
-
Open the
SampleScene
scene located inAssets/Scenes
. -
Create a new Security Profile.
-
Create your app in the Amazon Developer portal, and in 'New app Submission/Upload your app', you'll get an Appstore Certificate Hashes link. On clicking that link, you'll get the MD5 and SHA-256 of the Amazon signature with which your app will be signed when submitted. Use these hash values while adding Android Settings to your Security Profile to get the API key.
-
Once your API key is created, place it in
Assets/assets/api_key.txt
. -
Extract the login-with-amazon.jar fron the previously downloaded Login with Amazon SDK 3.1.2 zip file and place it inside
LwaAuthenticationManagerBridge/bin
. -
Build the game for the Android platform.
-
Install the built APK on any device with the Amazon AppStore.
-
Open the application, and you'll find a 'Login with Amazon' button activated, while the 'Sign Out' button remains inactive.
-
Upon selecting the 'Login with Amazon' button, you'll be redirected to a browser where you'll be prompted to enter your Amazon credentials.
-
After successfully logging in, you'll be asked to grant permission for the application to access your customer profile information.
-
Upon granting permission, you'll be redirected back to the application, where your Account, Name, Email, and Zip Code details will be displayed.
-
Subsequently, the 'Sign Out' button will become active, allowing you to log out and remove your information by clicking it.
-
Upon completion, the 'Login with Amazon' button will be reactivated, while the 'Sign Out' button returns to an inactive state.
We integrated the Login with Amazon SDK in our Unity project by creating a wrapper following the Unity plugin guidelines and recommended code for Login with Amazon Java integration.
-
Create a
LwaAuthenticationManagerBridge
folder insidePlugins/Android
, where you'll be placing the JAR and other scripts. -
Once the folder is created, download the login-with-amazon.jar and place it inside
LwaAuthenticationManagerBridge/bin
. -
Go to
Edit > Project Settings > Player > Android > Publishing Settings
, and check 'Custom Main Manifest', 'Custom Main Gradle Template', and 'Custom Gradle Setting Template'. -
In
gradleTemplate.properties
, addandroid.useAndroidX=true
. -
Create a new Security Profile.
-
Create your app in the Amazon Developer portal, and in 'New app Submission/Upload your app', you'll get an Appstore Certificate Hashes link. On clicking that link, you'll get the MD5 and SHA-256 of the Amazon signature with which your app will be signed when submitted. Use these hash values while adding Android Settings to your Security Profile to get the API key.
-
In the
Assets
folder, create anassets
folder and insert your API key as the only data in theapi_key.txt
-
In
mainTemplate.gradle
, add the following code snippet at the very end of the file:dependencies { implementation 'androidx.appcompat:appcompat:1.0.0' } task copyAmazon(type: Copy) { def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/") from unityProjectPath + '/Assets/assets/api_key.txt' into new File(projectDir, 'src/main/assets') } preBuild.dependsOn(copyAmazon)
-
In the folder created in Step 1, add three files that create a bridge between Login with Amazon Java APIs and Unity C# script. These code snippets can be refactored as per your requirements:
UnityPlayerProxyActivity.java
: Create a custom Unity activity following the Unity documentation and integrate Login with Amazon as documented in the official guide.LwaAuthManager.cs
: C# file to call the Java API for execution in Unity.UnityAuthListenerCallbackInterface.java
: Interface to handle authentication callbacks.
-
In
AndroidManifest.xml
, make the following changes:
- Replace the application's activity
android:name
with<packageName>.UnityPlayerProxyActivity
. - Add the WorkflowActivity. Don't forget to replace
${applicationId}
with your package name for this app. - Add network permissions:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
-
Add Android Settings to your security profile in the Developer portal by using the MD5 and SHA-256 values of your debug signature. An API key will be generated, which needs to be placed in the
Assets/assets/api_key.txt
file. -
Build the APK and sign it with the debug signature.
-
Install the APK on your device and test.
-
Add Android Settings to your security profile in the Amazon developer portal by using the MD5 and SHA-256 values present in Appstore Certificate Hashes by following the Pre-requisite Step 3. An API key will be generated, which needs to be placed in the
Assets/assets/api_key.txt
file. -
Build your APK and submit it for Live App Testing (LAT).
-
Once the LAT is submitted, after a few minutes, you'll receive an email to test your app on the device.
We welcome contributions to enhance the project! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with descriptive messages.
- Push your changes to your forked repository.
- Submit a pull request to the main repository.
For major changes, please open an issue first to discuss the proposed changes.
This project is licensed under the MIT-0 License.
If you found a bug or want to suggest a new [feature/use case/sample], please file an issue.
If you have questions, comments, or need help with code, we're here to help:
- Ask questions in the Amazon developer community space
- Ask questions on Stack Overflow using the amazon-appstore tag
Get the most up to date Amazon Appstore developer news, product releases, tutorials, and more:
- ๐ฃ Follow @AmazonAppDev and our team on Twitter
- ๐บ Subscribe to our Youtube channel
- ๐ง Sign up for the Developer Newsletter