Skip to content

ekrmh/firebase-auth-with-huawei-id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Firebase Auth with Huawei ID

Firebase Auth

Introduction

In this repo contains that sample to use custom auth tokens to Sign In Firebase with Huawei ID.

As is known, Firebase Auth is a GMS dependent service, so it cannot work on non-GMS devices. Instead, we will use Firebase Auth Rest API.

I used heroku as a backend server but instead, also you can use Firebase Cloud Functions, HMS Cloud Functions or your own backend server.

You can see flow at the below.

Flow

1. Request Authorization Code
Send an authorization request to Huawei Account Server and start login flow.
2. Obtain ID Token
After sign-in authorization is successfully , call the HuaweiAuthManager.parseAuthResultFromIntent method of onActivityResult and obtain ID Token, display name, profile picture etc.
3. Verify ID Token (Optional*)
This is an optional step. If you want, you can verify user ID token locally on client or verify on Huawei server on your backend.

Verify ID Token

4. Get user or create new user
Bring the user from Firebase according to the uid or create a new user.
5. Create Firebase Auth Custom Token
Create custom token using the Firebase Admin SDK on your backend server.

Firebase Custom Tokens

6. Login with custom token using Firebase Auth
Exchange custom token for an ID and refresh token.

Firebase Auth Rest Custom Token

Setup

AppGallery & Android

  • Enable Account Kit
  • Add agconnect-services.json into the your android project. ( android\app )

Firebase & Android

  • Enable Firebase Auth
  • Configure Firebase Admin SDK and add it into your server project.
  • Add serviceAccountKey.json into the your server project. ( heroku_server )
  • Add google-services.json into the your android project. ( android\app )
  • Configure WEB <API_KEY>.(android\app\src\main\java\com\ekrmh\firebasehuaweiauth\util\NetworkSingleton.kt)

Backend & Android

  • Configure <DATABASE_URL> (heroku_server/index.js)
  • Configure your server url. <YOUR_SERVER_URL> (android\app\src\main\java\com\ekrmh\firebasehuaweiauth\util\NetworkSingleton.kt)

Author

Ekrem Hatipoglu ekrem.hatipoglu@huawei.com

If you encounter any problems, you can always contact me.