我正在尝试使用MSAL通过B2C的ROPC流获取访问令牌。但是,它尝试使用常规AAD(而非B2C)用户领域发现失败,这显然失败了,因为用户ID没有域。
Fiddler显示MSAL执行的调用之一是:https://login.microsoftonline.com/common/userrealm/user1?api-version=1.0。注意“ user1”,它是B2C中的有效用户ID,而不是AAD中的有效ID。
Authority = "https://login.microsoftonline.com/tfp/mrochonb2cprod.onmicrosoft.com/B2C_1_ROP/.well-known/openid-configuration";
var pwd = new SecureString();
foreach (var c in "...") pwd.AppendChar(c);
var app = PublicClientApplicationBuilder
.Create(ClientId)
.WithB2CAuthority(Authority)
.Build();
var ar = await app.AcquireTokenByUsernamePasswordAsync(Scopes, "user1", pwd);
答案 0 :(得分:1)
我已经与Microsoft工程师确认了这一点。目前,他们还没有与B2C用户一起测试MSAL aquiretokenusernamepassword()
方法,对此还没有示例。此功能在公共预览中。他们已经使用iOS的AppAuth和Android的AppAuth在生产中广泛测试了此流程。您可以找到更多详细信息here。
但是ropc流程工作正常,您可以改用发布请求。
POST /yourtenant.onmicrosoft.com/oauth2/v2.0/token?p=B2C_1_ROPC_Auth HTTP/1.1
Host: yourtenant.b2clogin.com
Content-Type: application/x-www-form-urlencoded
username=leadiocl%40trashmail.ws&password=Passxword1&grant_type=password&scope=openid+bef22d56-552f-4a5b-b90a-1988a7d634ce+offline_access&client_id=bef22d56-552f-4a5b-b90a-1988a7d634ce&response_type=token+id_token
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik9YQjNhdTNScWhUQWN6R0RWZDM5djNpTmlyTWhqN2wxMjIySnh6TmgwRlkifQ.eyJpc3MiOiJodHRwczovL3RlLmNwaW0ud2luZG93cy5uZXQvZjA2YzJmZTgtNzA5Zi00MDMwLTg1ZGMtMzhhNGJmZDllODJkL3YyLjAvIiwiZXhwIjoxNTEzMTMwMDc4LCJuYmYiOjE1MTMxMjY0NzgsImF1ZCI6ImJlZjIyZDU2LTU1MmYtNGE1Yi1iOTBhLT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E1Yi1iOTBhLTE5ODhhN2Q2MzRjZSIsImFjciI6ImIyY18xYV9yZXNvdXJjZW93bmVydjIiLCJpYXQiOjE1MTMxMjY0NzgsImF1dGhfdGltZSI6MTUxMzEyNjQ3OCwib2lkIjoiM2MzYjk2OWMtOGM0OS00ZTExLWE0ZWYtZmRiMmYzOTJmMDQ5IiwiYXRfaGFzaCI6Ikd6QUNCTVJtcklwYm9OdkFtNHhMWEEifQ.iAJg13cgySsdH3cmoEPGZB_g-4O8KWvGr6W5VzRXtkrlLoKB1pl4hL6f_0xOrxnQwj2sUgW-wjsCVzMc_dkHSwd9QFZ4EYJEJbi1LMGk2lW-PgjsbwHPDU1mz-SR1PeqqJgvOqrzXo0YHXr-e07M4v4Tko-i_OYcrdJzj4Bkv7ZZilsSj62lNig4HkxTIWi5Ec2gD79bPKzgCtIww1KRnwmrlnCOrMFYNj-0T3lTDcXAQog63MOacf7OuRVUC5k_IdseigeMSscrYrNrH28s3r0JoqDhNUTewuw1jx0X6gdqQWZKOLJ7OF_EJMP-BkRTixBGK5eW2YeUUEVQxsFlUg"
}
答案 1 :(得分:0)
MSAL.NET v3.0.5-preview+使用ROPC流程与B2C一起使用。有关使用MSAL的更多信息,请参见此section of the MSAL.NET wiki。