-
Notifications
You must be signed in to change notification settings - Fork 343
Xamarin Android specifics 2x
Jean-Marc Prieur edited this page Apr 12, 2019
·
3 revisions
bool useEmbeddedWebView = false;
var authResult = AcquireToken(scopes, parentActivity)
.WithEmbeddedWebView(useEmbeddedWebView)
.ExecuteAsync()
;
You need to call an overload of AcquireTokenAsync
that uses UIParent
, which needs to be initialized with an Activity.
// From an activity class
var uiParent = new UIParent(this, useEmbeddedWebview: true);
On Android, you need to override the OnActivityResult
method of the Activity
and call the SetAuthenticationContinuationEventArgs method of the AuthenticationContinuationHelper MSAL class.
protected override void OnActivityResult(int requestCode,
Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode,
resultCode,
data);
}
That line ensures that the control goes back to MSAL once the interactive portion of the authentication flow ended.
The AndroidManifest.xml
should contain the following values:
<activity android:name="microsoft.identity.client.BrowserTabActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="msal{client_id}" android:host="auth" />
</intent-filter>
</activity>
More details are provided in the Android Specific Considerations paragraph of the following sample's readme.md file:
Sample | Platform | Description |
---|---|---|
https://github.com/Azure-Samples/active-directory-xamarin-native-v2 | Xamarin iOS, Android, UWP | A simple Xamarin Forms app showcasing how to use MSAL to authenticate MSA and Azure AD via the AADD v2.0 endpoint, and access the Microsoft Graph with the resulting token. |
- Home
- Why use MSAL.NET
- Is MSAL.NET right for me
- Scenarios
- Register your app with AAD
- Client applications
- Acquiring tokens
- MSAL samples
- Known Issues
- AcquireTokenInteractive
- WAM - the Windows broker
- .NET Core
- Maui Docs
- Custom Browser
- Applying an AAD B2C policy
- Integrated Windows Authentication for domain or AAD joined machines
- Username / Password
- Device Code Flow for devices without a Web browser
- ADFS support
- Acquiring a token for the app
- Acquiring a token on behalf of a user in Web APIs
- Acquiring a token by authorization code in Web Apps
- High Availability
- Token cache serialization
- Logging
- Exceptions in MSAL
- Provide your own Httpclient and proxy
- Extensibility Points
- Clearing the cache
- Client Credentials Multi-Tenant guidance
- Performance perspectives
- Differences between ADAL.NET and MSAL.NET Apps
- PowerShell support
- Testing apps that use MSAL
- Experimental Features
- Proof of Possession (PoP) tokens
- Using in Azure functions
- Extract info from WWW-Authenticate headers
- SPA Authorization Code