Welcome to the Sign-in with Phone Android project! This project demonstrates a seamless user authentication flow in an Android app using JSON Web Tokens (JWT) and the Activity Result API.
Follow the steps below to incorporate the "Login with Phone" feature into your Android app:
-
Acquire the API Key: Obtain the necessary API key from Phone Email Admin Dashboard to enable secure communication with the authentication service.
-
Implementing the Login Button: In your app's login screen, implement the login button click listener to launch the
AuthActivity
using the Activity Result API. -
Handling Results with the Launcher: Register an activity result launcher to handle the result of the
AuthActivity
, extracting the access token from the result data. -
Implementing AuthActivity: AuthActivity is responsible for verifying the phone number through a web-based authentication process. Upon successful verification, the access token is obtained from a JavaScript interface and set as the result. Replace the placeholder client id in AppConstants (CLIENT_ID) with your account client id.
-
Managing the Access Token in the Calling Activity: Handle the access token obtained from the
AuthActivity
within the calling activity'slauncher
callback, enabling further actions based on the access token. -
Conclusion: Customize the authentication logic and error handling based on your app's requirements.
The project is organized as follows:
- `app`: Contains the main Android application code.
- `MainActivity`: Entry point of the app with the login button implementation.
- `AuthActivity`: Manages the phone number verification through a WebView and JavaScript interface.
- Other relevant files and resources.
- AndroidX
- WebView
- retrofit
Clone the repository and open the project in Android Studio. Follow the steps outlined in the "Getting Started" section to integrate the "Login with Phone" feature into your app.
Feel free to contribute to the project by opening issues or submitting pull requests. Your feedback and suggestions are highly appreciated.
This project is licensed under the MIT License.
Happy coding!