Get up and running in minutes
Getting Started: Android
The following steps allow you to quickly sign in users to your application using their work or school accounts.
We built this sample using Android 24, with Android Studio 2.1.2 and Java 8.
1. Register an app to get a client ID
Register your app to get a client ID and access a personalized version of these instructions. If you already have a client ID for an app with the implicit flow enabled you can skip to the next step.Register your app
2. Set up the SDK
Copy and paste the following snippet of code into the dependencies block in your app/build.gradle file.
Add the following required permissions to your AndroidManifest.xml file, inside the <Manifest> tag.
3. Add sign in logic
Copy and paste the following code into your activity's *.java file where you would like the sign in flow.
In the same file, copy and paste the following configurations into your Java class outside of any method. Then set the value of the CLIENT_ID and REDIRECT_URI variables to your application's corresponding values.
In the same file, copy and paste the following method below onCreate(…).
4. Add a button for sign in
Copy and paste the following snippet of code into the activity's *.xml layout.
5. Try it out
Build and run your application. Then click the button to launch a browser window that will authenticate the user. After completing authentication, the SDK will provide you with information about the user who authenticated based on the contents of the token provided by Microsoft.
In order to test your application, you will need at least one work account (such as an Office 365 Subscription or Azure Active Directory user account). You can learn how to create one here.
At this point the token has not been validated. The token must be validated before you can use it to access services or data that you control.
Next Steps: Securing your Web API
Call your application’s backend service/API to validate the token and authenticate users to your backend service. Learn more here