Skip to content

Commit c3c494c

Browse files
Additional content and linking to MS Learn
1 parent 2e57fa4 commit c3c494c

1 file changed

Lines changed: 14 additions & 92 deletions

File tree

README.md

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66

77
## Overview
88

9-
MSAL Android is a library that enables Android applications to authenticate users with Microsoft identity platform (formerly Azure Active Directory) and access protected web APIs using OAuth2 and OpenID Connect protocols. The Microsoft Authentication Library (MSAL) for Android enables developers to acquire security tokens from the Microsoft identity platform to authenticate users and access secure web APIs for their Android based applications.
9+
MSAL Android is a library that enables Android applications to authenticate users with Microsoft identity platform and access protected web APIs using OAuth2 and OpenID Connect protocols. The Microsoft Authentication Library (MSAL) for Android enables developers to acquire security tokens from the Microsoft identity platform to authenticate users and access secure web APIs for their Android based applications.
1010

1111
MSAL Android supports multiple authentication scenarios, such as single sign-on (SSO), conditional access, and brokered authentication. MSAL Android also provides native authentication APIs that allow applications to implement a native experience with end-to-end customizable flows.
1212

1313
[![Version Badge](https://img.shields.io/maven-central/v/com.microsoft.identity.client/msal.svg)](https://repo1.maven.org/maven2/com/microsoft/identity/client/msal/)
1414

15-
## Migrating from ADAL
16-
17-
The Azure Active Directory Authentication Library (ADAL) for Android was deprecated on June 2023. Follow the [ADAL to MSAL migration guide for Android](https://docs.microsoft.com/azure/active-directory/develop/migrate-android-adal-msal) to avoid putting your app's security at risk..
18-
1915
## Getting started
2016

2117
To use MSAL Android in your application, you need to register your application in the Microsoft Entra Admin center and configure your Android project. Since MSAL Android supports both browser-delegated and native authentication experiences, follow the steps in the following tutorials based on your scenario.
2218

23-
* For browser-delegated scenarios, refer to the quickstart, [Sign in users and call Microsoft Graph from an Android app](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-mobile-app-android-sign-in).
19+
* For browser-delegated authentication scenarios, refer to the quickstart, [Sign in users and call Microsoft Graph from an Android app](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-mobile-app-android-sign-in).
20+
21+
* For native authentication scenarios, refer to the Microsoft Entra External ID sample guide, [Run Android Kotlin sample app](https://review.learn.microsoft.com/en-us/entra/external-id/customers/tutorial-native-authentication-prepare-android-app?branch=release-native-auth-public-preview).
22+
2423

25-
* For Native Authentication scenarios, refer to the Microsoft Entra External ID sample guide, [Run Android Kotlin sample app](https://review.learn.microsoft.com/en-us/entra/external-id/customers/tutorial-native-authentication-prepare-android-app?branch=release-native-auth-public-preview).
24+
## Migrating from ADAL
2625

26+
The Azure Active Directory Authentication Library (ADAL) for Android was deprecated on June 2023. Follow the [ADAL to MSAL migration guide for Android](https://docs.microsoft.com/azure/active-directory/develop/migrate-android-adal-msal) to avoid putting your app's security at risk.
2727

2828
## Using MSAL Android
2929

@@ -37,7 +37,7 @@ To use MSAL Android in your application, you need to register your application i
3737

3838
Add the following dependencies to your app's build.gradle:
3939

40-
**For browser-delegated authentication:**
40+
**Browser-delegated authentication:**
4141

4242
```gradle
4343
dependencies {
@@ -53,7 +53,7 @@ maven {
5353
}
5454
```
5555

56-
**For Native authentication:**
56+
**Native authentication:**
5757

5858

5959
```java
@@ -84,7 +84,7 @@ In the `redirect_uri`, the `<YOUR_PACKAGE_NAME>` refers to the package name retu
8484

8585
The values above are the minimum required configuration. MSAL relies on the defaults that ship with the library for all other settings. Please refer to the [MSAL Android configuration file documentation](https://learn.microsoft.com/en-us/entra/msal/android/msal-configuration) to understand the library defaults.
8686

87-
**For Native authentication:**
87+
**Native authentication:**
8888

8989
1. Right-click res and choose New > Directory. Enter raw as the new directory name and select OK.
9090
1. In this new folder (app > src > main > res > raw), create a new JSON file called auth_config_native_auth.json and paste the following template MSAL Configuration:
@@ -107,7 +107,7 @@ The values above are the minimum required configuration. MSAL relies on the def
107107
}
108108
```
109109

110-
### Step 3: Configure the AndroidManifest.xml
110+
### Step 3: Configure the AndroidManifest.xml for browser-delegated authentication
111111

112112
1. Request the following permissions via the Android Manifest
113113

@@ -138,90 +138,12 @@ The values above are the minimum required configuration. MSAL relies on the def
138138

139139
>NOTE: Please refer to the [frequently asked questions](https://learn.microsoft.com/en-us/entra/msal/android/frequently-asked-questions) for more information on common redirect uri issues.
140140
141-
### Step 4: Create an MSAL PublicClientApplication
142-
143-
>NOTE: In this example we are creating an instance of MultipleAccountPublicClientApplication, which is designed to work with apps that allow multiple accounts to be used within the same application. If you would like to use SingleAccount mode, refer to the [single vs. multi account documentation](https://docs.microsoft.com/azure/active-directory/develop/single-multi-account). You can also check out the [quickstart](https://docs.microsoft.com/azure/active-directory/develop/quickstart-v2-android) for examples of how this is used.
144-
145-
1. Create a new MultipleAccountPublicClientApplication instance.
146141

147-
```Java
148-
149-
String[] scopes = {"User.Read"};
150-
IMultipleAccountPublicClientApplication mMultipleAccountApp = null;
151-
IAccount mFirstAccount = null;
152-
153-
PublicClientApplication.createMultipleAccountPublicClientApplication(getContext(),
154-
R.raw.msal_config,
155-
new IPublicClientApplication.IMultipleAccountApplicationCreatedListener() {
156-
@Override
157-
public void onCreated(IMultipleAccountPublicClientApplication application) {
158-
mMultipleAccountApp = application;
159-
}
160-
161-
@Override
162-
public void onError(MsalException exception) {
163-
//Log Exception Here
164-
}
165-
});
166-
```
167-
168-
2. Acquire a token interactively
169-
170-
```java
171-
172-
mMultipleAccountApp.acquireToken(this, SCOPES, getAuthInteractiveCallback());
173-
174-
private AuthenticationCallback getAuthInteractiveCallback() {
175-
return new AuthenticationCallback() {
176-
@Override
177-
public void onSuccess(IAuthenticationResult authenticationResult) {
178-
/* Successfully got a token, use it to call a protected resource */
179-
String accessToken = authenticationResult.getAccessToken();
180-
// Record account used to acquire token
181-
mFirstAccount = authenticationResult.getAccount();
182-
}
183-
@Override
184-
public void onError(MsalException exception) {
185-
if (exception instanceof MsalClientException) {
186-
//And exception from the client (MSAL)
187-
} else if (exception instanceof MsalServiceException) {
188-
//An exception from the server
189-
}
190-
}
191-
@Override
192-
public void onCancel() {
193-
/* User canceled the authentication */
194-
}
195-
};
196-
}
197-
```
198-
199-
3. Acquire a token silently
200-
201-
```java
202-
203-
/*
204-
Before getting a token silently for the account used to previously acquire a token interactively, we recommend that you verify that the account is still present in the local cache or on the device in case of brokered auth
205-
206-
Let's use the synchronous methods here which can only be invoked from a Worker thread
207-
*/
208-
209-
//On a worker thread
210-
IAccount account = mMultipleAccountApp.getAccount(mFirstAccount.getId());
211-
212-
if(account != null){
213-
//Now that we know the account is still present in the local cache or not the device (broker authentication)
214-
215-
//Request token silently
216-
String[] newScopes = {"Calendars.Read"};
217-
218-
String authority = mMultipleAccountApp.getConfiguration().getDefaultAuthority().getAuthorityURL().toString();
142+
### Step 4: Create an MSAL PublicClientApplication
219143

220-
//Use default authority to request token from pass null
221-
IAuthenticationResult result = mMultipleAccountApp.acquireTokenSilent(newScopes, account, authority);
222-
}
144+
For browser-delegated authentication, you'll need to create an instance of the PublicClientApplication, before you can acquire a token silently or interactively. Please proceed to the official MSAL Android documentation on how to [instantiate your client application and acquire tokens](https://learn.microsoft.com/en-us/entra/msal/android/acquire-tokens)
223145

224-
```
146+
For a native authentication experience, you can optionally complete [additional logging configuration](https://review.learn.microsoft.com/en-us/entra/external-id/customers/tutorial-native-authentication-prepare-android-app?branch=release-native-auth-public-preview#create-sdk-instance), and proceed to creating an instance of the client application using the configuration we created in step 2. Learn more by following the [Native auth Android app tutorial](https://review.learn.microsoft.com/en-us/entra/external-id/customers/tutorial-native-authentication-prepare-android-app?branch=release-native-auth-public-preview#create-sdk-instance)
225147

226148
## ProGuard
227149
MSAL uses reflection and generic type information stored in `.class` files at runtime to support various persistence and serialization related functionalities. Accordingly, library support for minification and obfuscation is limited. A default configuration is shipped with this library; please [file an issue](https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/new/choose) if you find any issues.

0 commit comments

Comments
 (0)