You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This method is invoked every time the application is started. It's used as an opportunity to process the response from the broker and complete the authentication process that MSAL.NET started.
@@ -93,28 +93,28 @@ To set up the object window:
93
93
1. On the `AcquireTokenInteractive` call, use `.WithParentActivityOrWindow(App.RootViewController)` and then pass in the reference to the object window you'll use.
MSAL.NET supports only the Xamarin.iOS platform. It doesn't yet support brokers for the Xamarin.Android platform.
202
+
### Step 1: Enable broker support
203
+
204
+
Broker support is enabled on a per-PublicClientApplication basis. It's disabled by default. Use the `WithBroker()` parameter (set to true by default) when creating the `IPublicClientApplication` through the `PublicClientApplicationBuilder`.
### Step 2: Update AppDelegate to handle the callback
215
+
216
+
When MSAL.NET calls the broker, the broker will, in turn, call back to your application with the OnActivityResult() method. Since MSAL will wait for the response from the broker, your application needs to route the result to MSAL.NET.
217
+
This can be achieved by routing the result to the `SetAuthenticationContinuationEventArgs(int requestCode, Result resultCode, Intent data)` by overriding the OnActivityResult() method as shown below
This method is invoked every time the broker application is launched and is used as an opportunity to process the response from the broker and complete the authentication process started by MSAL.NET.
228
+
229
+
### Step 3: Set an Activity
230
+
231
+
For brokered authentication to work you'll need to set an activity so that MSAL can send and receive the response from broker.
232
+
233
+
To do this, you'll need to provide the activity(usually the MainActivity) to the `WithParentActivityOrWindow(object parent)` as the parent object.
234
+
235
+
**For example:**
236
+
237
+
In the Acquire Token call:
238
+
239
+
```CSharp
240
+
result=awaitapp.AcquireTokenInteractive(scopes)
241
+
.WithParentActivityOrWindow((Activity)context))
242
+
.ExecuteAsync();
243
+
```
244
+
245
+
### Step 4: Register your RedirectUri in the application portal
246
+
247
+
MSAL uses URLs to invoke the broker and then return back to your app. To complete that round trip, you need to register a URL scheme for your app. This Redirect URI needs to be registered on the Azure AD app registration portal as a valid redirect URI for your application.
248
+
249
+
250
+
The redirect URI needed for your application is dependent on the certificate used to sign the APK.
The last part of the URI, `hgbUYHVBYUTvuvT&Y6tr554365466=`, is the signature that the APK is signed with, base64 encoded.
257
+
However, during the development phase of your application using Visual Studio, if you're debugging your code without signing the apk with a specific certificate, Visual Studio will sign the apk for you for debugging purposes, giving the APK a unique signature for the machine that it's built on. Thus, each time you build your app on a different machine, you'll need to update the redirect URI in the application's code and the application's registration in the Azure portal in order to authenticate with MSAL.
258
+
259
+
While debugging, you may encounter an MSAL exception (or log message) stating the redirect URI provided is incorrect. **This exception will also provide you with the redirect URI that you should be using** with the current machine you are debugging on. You can use this redirect URI to continue developing for the time being.
260
+
261
+
Once you are ready to finalize your code, be sure to update the redirect URI in the code and on the application's registration in the Azure portal to use the signature of the certificate you will be signing the APK with.
262
+
263
+
In practice, this means that you have to register a redirect URI for each member of the team, plus a redirect URI for the production signed version of the APK.
264
+
265
+
You can also compute this signature yourself, similar to how MSAL does it:
// Server side needs to register all other tags. ADAL will
294
+
// send one of them.
295
+
}
296
+
}
297
+
```
298
+
299
+
You also have the option of acquiring the signature for your package by using the keytool with the following commands:
300
+
301
+
For Windows: `keytool.exe -list -v -keystore "%LocalAppData%\Xamarin\Mono for Android\debug.keystore" -alias androiddebugkey -storepass android -keypass android`
199
302
200
-
The MSAL Android native library already supports brokered authentication. For more information, see [Brokered authentication in Android](brokered-auth.md).
0 commit comments