简体   繁体   中英

How to Integrate existing Azure AD B2C into a Xamarin forms app using MSAL?

I am kind of confused about the integration process , so I hope to get some clearer guidance in my case.

Let say there is an existing web application(Angular +.Net Core) and I am working on the mobile version(Xamarin.Forms) for it. The web side and mobile side will share the same API backend for user authentication and other services.

So there is an existing tenant and related information (tenantName, tenantID, AppID, RedirectURL, policies, etc), and the redirectURL is for authorizing (https://.../authorize).

At first I thought I can directly used this information. I tried on the code sample and just replaced tenantName, tenantID... When I clicked Log In button, it first showed me this error: 在此处输入图像描述

And then it directed me to the Sign In page. Finally, I signed in the web application in the simulator.

I feel like I should register the mobile app under the same tenant. If I want to help current web users log in the mobile version, how to integrate the existing Azure B2C properly with it for the authentication? Any hits would be appreciated. Thanks in advance.

Update: I stayed stuck in the token part. I already enabled implicit grant. I used the sample code and add scope in the sample: 在此处输入图像描述

在此处输入图像描述

When you Register a web application , you should pay attention to the content after step 9.

Once the application registration is complete, enable the implicit grant flow:

  1. In the left menu, under Manage, select Authentication.
  2. Under Implicit grant, select both the Access tokens and ID tokens check boxes.
  3. Select Save.

Select the Access tokens will give you the access token.

Ok finally get the access token in the AuthenticationResult. This is how I dealt with it.

After we define a scope, we need to configured permission.

Go to the registered application and add it to the configured permissions list:

在此处输入图像描述

在此处输入图像描述

After that I can see the accessToken in the result when I debug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM