Native Provider - Google
You can use Google AuthProvider to log in with or without Lock. Make sure to follow the instructions in the setup section. Lock-Google.Android requires Android API 15 or later & Google Play Services 10.+Latest version of Lock-Google
The Lock-Google is available through Maven Central and JCenter. To install it, simply add the following line to yourbuild.gradle:
compile 'com.auth0.android:lock-google:1.+'
You can check for the latest version on the repository Readme, in Maven, or in JCenter.
Lock-Google Setup
Google Developers Console
- Go to the Google Developers Console and create a new Project.
- Complete the OAuth Consent Screen by at least providing a valid Email Address and Name.
- On the left side you have the navigation drawer, click Credentials.
- Create a new credential by clicking the Create Credentials button and choosing OAuth client ID. Next, choose Web Application and give it a name like “Auth0 Server Google-OAuth”. Complete the Authorized redirect URIs by filling the field with your callback URL, which should look like
https://{yourDomain}/login/callback. Make sure to press ENTER before leaving the field and then click the Create button. Take note of theCLIENT IDandCLIENT SECRETvalues as we’re going to use them later. - Create a new credential by clicking the Create Credentials button and choosing OAuth client ID. Next, choose Android and give it a name like “Auth0 Android Google-OAuth”. Obtain the SHA-1 of the certificate you’re using to sign your application and complete the first field with it. If you need help obtaining the SHA-1 check this section. Finally, complete the last field with your android application Package Name and then click the Create button. Take note of the
CLIENT IDvalue as we’re going to use it later.
Auth0 Dashboard
- Go to the Auth0 Dashboard and click Social Connections.
- Click Google and a dialog will prompt.
- Complete the “Client ID” field with the
CLIENT IDvalue obtained in the step 4 of the Google Developers Console section above. - Complete the “Client Secret” field with the
CLIENT SECRETvalue obtained in the step 4 of the Google Developers Console section above. - Complete the “Allowed Mobile Client IDs” field with the
CLIENT IDobtained in the step 5 of the Google Developers Console section above. - Click the Save button.
- Go to the Auth0 Dashboard and click Applications. If you haven’t created yet one, do that first and get into your application configuration page.
- At the bottom of the page, click the “Show Advanced Settings” link and go to the “Device Settings” tab.
- In the Android section, complete the Package Name with your application’s package name. Finally, complete the Key Hashes field with the SHA-256 of the certificate you’re using to sign your application. If you need help obtaining the SHA-256 check this section. Click the “Save Changes” button.
Android application
-
In your android application, create a new String resource in the
res/strings.xmlfile. Name itgoogle_server_client_idand set as value theCLIENT_IDobtained in the step 5 of the Google Developers Console setup section above. -
Add the Google Play Services version MetaData to the
AndroidManifest.xmlfile, inside the Application tag. -
Add the Internet Android permission to your
AndroidManifest.xmlfile. -
When creating a new instance of the
GoogleAuthProviderpass thegoogle_server_client_idvalue obtained previously as the first parameter:
Usage without Lock
If you plan to use this provider without Lock, make sure you override theonActivityResult() method and redirect the call to the provider instance. Finally, call start to begin the authentication process.
Additional Options
Using a custom connection name
To use a custom social connection name to authorize against Auth0, create the GoogleAuthProvider instance using the second constructor:Send additional authentication parameters
To send additional parameters on the authentication callsetParameters.
Requesting a custom Google scope
By default, the scopeScopes.PLUS_LOGIN is requested. You can customize the Scopes by calling setScopes with the list of Scopes. Each Google API (Auth, Drive, Plus..) specify its own list of Google Scopes.
Requesting custom Android runtime permissions
This provider doesn’t require any special Android Manifest Permissions to authenticate the user. But if your use case requires them, you can let the AuthProvider handle them for you. Use thesetRequiredPermissions method.
ActivityCompat.OnRequestPermissionsResultCallback interface. When the onRequestPermissionsResult method gets called pass the result to the provider by calling provider.onRequestPermissionsResult.
Log out / clear account.
To log out the user so that the next time they are prompted to input their credentials callclearSession. After you do this the provider state will be invalid and you will need to call start again before trying to authorize a result. Calling stop has the same effect.
provider.clearSession();
Remember the last login
By default this provider will remember the last account used to log in. If you want to change this behavior, use the following method.provider.rememberLastLogin(false);
Certificate fingerprints
When creating a new Credential in the Google Developers Console you will need to provide the SHA-1 of the certificate you’re using to sign your application. When completing your Application’s Configuration in the you will also need to provide the SHA-256 value. Here is an example of the terminal command to acquire the value, and a sample result. Command:keytool -exportcert -alias androiddebugkey -keystore <PATH_TO_YOUR_KEYSTORE> -storepass android | openssl sha1 -binary | openssl base64
Sample output:
no71633JAC3qgzQYCbskprUr55k=
If you need assistance, you can follow this Keystores Guide to acquire those values.
Native Provider - Facebook
You can use Facebook AuthProvider to log in with or without Lock. Make sure to follow the instructions in the setup section. Lock-Facebook requires Android API 15 or later & Facebook Android SDK 4.+Latest version
The Lock-Facebook is available through Maven Central and JCenter. To install it, simply add the following line to yourbuild.gradle:
compile 'com.auth0.android:lock-facebook:3.+'
You can check for the latest version on the repository Readme, in Maven, or in JCenter.
Lock-Facebook Setup
Facebook Developers Console
- Go to the Facebook Developers Console and create a new App: Choose “Android” and give it a valid name. Click “Create new Facebook App ID”.
- Add your application’s Package Name and the name of the Activity class where you’re using the provider and click the Next button.
- Add the SHA-1 Base64 encoded Key Hashes of the certificates you’re using to sign your application and click the Next button. If you need help obtaining the SHA-1 check this section.
- Finally, scroll to the top of the page and click the Skip Quickstart button to go to your Facebook app’s page.
- On the top of the page, you will find the
APP IDandAPP SECRETvalues. Save them as you’re going to need them later. - On the left side you have the navigation drawer. Click Settings and then Basic. Turn ON the Single Sign-On switch and click the Save button.
- Click Settings and then Advanced. Turn ON the Native or desktop app? switch.
Auth0 dashboard
- Go to the Auth0 Dashboard and click Social Connections.
- Click Facebook and a dialog will prompt.
- Complete the “App ID” field with the
APP IDvalue obtained in the step 5 of the Facebook Developers Console section above. - Complete the “App Secret” field with the
APP SECRETvalue obtained in the step 5 of the Facebook Developers Console section above. - Click the Save button.
- Go to the Auth0 Dashboard and click Applications. If you haven’t created yet one, do that first and get into your application configuration page.
- At the bottom of the page, click the “Show Advanced Settings” link and go to the “Device Settings” tab.
- In the Android section, complete the Package Name with your application’s package name. Finally, complete the Key Hashes field with the SHA-256 of the certificate you’re using to sign your application. If you need help obtaining the SHA-256 check this section. Click the “Save Changes” button.
Android application
-
In your android application, create a new String resource in the
res/strings.xmlfile. Name itfacebook_app_idand set as value theAPP IDobtained in the step 5 of the Facebook Developers Console setup section above. -
Add the
FacebookActivityandfacebook_app_idMetaData to theAndroidManifest.xmlfile, inside the Application tag. -
Add the Internet Android permission to your
AndroidManifest.xmlfile. -
Create a new instance of the
FacebookAuthProvider.
Usage without Lock
If you plan to use this provider without Lock, make sure you override theonActivityResult() method of your activity and redirect the call to the provider instance. Finally, call start to begin the authentication process.
Additional options
Using a custom connection name
To use a custom social connection name to authorize against Auth0, callsetConnection with your new connection name.
Send additional authentication parameters
To send additional parameters on the authentication callsetParameters.
Requesting custom Facebook permissions
By default, the permissionpublic_profile is requested. You can customize them by calling setPermissions with the list of Facebook Permissions.
Requesting custom Android runtime permissions
This provider doesn’t require any special Android Manifest Permissions to authenticate the user. But if your use case requires them, you can let the AuthProvider handle them for you. Use thesetRequiredPermissions method to specify them.
ActivityCompat.OnRequestPermissionsResultCallback interface. When the onRequestPermissionsResult method gets called pass the result to the provider by calling provider.onRequestPermissionsResult.
Log out / clear account.
To log out the user so that the next time they are prompted to input their credentials callclearSession. After you do this the provider state will be invalid and you will need to call start again before trying to authorize a result. Calling stop has the same effect.
provider.clearSession();
Remember the last Login
By default this provider will remember the last account used to log in. If you want to change this behavior, use the following method.provider.rememberLastLogin(false);
Certificate fingerprints
When creating a new OAuth Credential in the Facebook Developers Console you will need to provide the SHA-1 of the certificate you’re using to sign your application. When completing your Application’s Configuration in the Auth0 Dashboard you will also need to provide the SHA-256 value. Here is an example of the terminal command to acquire the value, and a sample result. Command:keytool -exportcert -alias androiddebugkey -keystore <PATH_TO_YOUR_KEYSTORE> -storepass android | openssl sha1 -binary | openssl base64
Sample output:
SHA1: BB:0D:AC:74:D3:21:E1:43:07:71:9B:62:90:AF:A1:66:6E:44:5D:75
SHA256: 15:B9:F9:33:9F:E4:E3:68:C2:10:49:17:5D:A8:77:12:7C:8E:57:E9:FF:B7:23:EA:CC:DD:56:08:06:C9:5E:33
If you need assistance, you can follow this Keystores Guide to acquire those values.