With the release of AppGallery Connect version 1.5.2 the Auth service now has full support for making use of unified sign-in with a Facebook account!
This new functionality makes AppGallery Connect Auth a great option for all of your app's authentication needs both on Huawei devices and other Android devices.
So how do we go about using unified sign-in with a Facebook account? Let's take a look!
Configuring the Facebook Login Environment
First, you'll need to configure the Facebook Login environment.
Select or create a Facebook app.
Edit your resource file. Copy the following code to the /app/res/values/strings.xml file of your Android project.
Edit your manifest file. Add the following uses-permission element following the application element in the /app/manifest/AndroidManifest.xml file of your Android project.
Copy the following meta-data element to the application element.
Associate your package name and default activity class with your app and click Save. Confirm the use of this package name (skip this if your app has not been released on Google Play).
Develop a key hash using the following command, and release it for your app.
If you haven't installed OpenSSL (openssl-for-windows) for your project, please go to Google Code Archive and download it as required.
The command format is as follows:
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH* | openssl sha1 -binary | openssl base64
The Facebook Login environment has now been successfully configured. Let's move on to the operations relevant to Auth Service.
Enabling Auth Service
Sign in to AppGallery Connect, create a project and an app, and enable Auth Service. You'll need to enter the App ID and App Secret for your app when enabling Facebook under Authentication modes, which can be found under Settings > Basic on Facebook for Developers. If they are not displayed, click the button following App Secret to show them.
Generating the Certificate Fingerprint for Your Android Project
If the demo project does not provide a Java KeyStore, go to Generate Signed Bundle or APK and click Create new.key store to create one
Generate an SHA-256 certificate fingerprint. Run the following command and enter the configured password to generate a SHA-256 certificate fingerprint.
Open the app-level build.gradle file, and configure the certificate information for your project
Click here to view the sample code.
Configure the generated SHA-256 certificate fingerprint in AppGallery Connect. (If you do not perform this step, error 6003 will be reported.)
Configure Your App
Open the project-level build.gradle file and configure information, including the Maven repository address. The code is as follows:
Open the app-level build.gradle file and configure information, including the SDK information and app plug-in address. The code is as follows:
Add the code for implementing unified sign-in:
Viewing the Result and Logs
Once you run your signed APK on an Android phone and call the FaceBookLogin method, you'll get the following page.
You can tap CONTINUE AS LINKING and sign in to your app with your Facebook account. The following log information will be displayed.
Compared with the traditional implementation mode, the unified sign-in has greatly simplified the development process. It is strongly recommended that you use the new mode.
For details about Auth Service, please refer to:
Auth Service document for Android
Guide for integrating Facebook account
Top comments (0)