Asp.net core asp.net核心身份验证AddMicrosoftAccount

Asp.net core asp.net核心身份验证AddMicrosoftAccount,asp.net-core,identityserver4,Asp.net Core,Identityserver4,我已将microsoft身份验证添加到我的应用程序中,如下所示: services.AddAuthentication() .AddMicrosoftAccount(options => { options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

我已将microsoft身份验证添加到我的应用程序中,如下所示:

 services.AddAuthentication()
                    .AddMicrosoftAccount(options =>
                    {
                        options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                        options.ClientId = Configuration["Authentication:Microsoft:ClientId"];
                        options.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
                        options.Scope.Add("openid profile email");
                    });
我不知道如何请求额外的作用域,上面的内容不起作用,因为“profile”或“email”的声明从未返回


有人知道怎么做吗?或者如果可能的话?

MicrosoftAccountOptions
包含默认的
graph.microsoft.com/user.read
范围,因此在完成流程后,您的
身份
应该拥有用户信息,而不需要任何额外的技巧。但是,
AddMicrosoftAccount
实际上是带有特定预设的
AddOAuth
,可以被视为过时。由于这个原因,它不能为您提供
openid
范围

最新的替代方案是使用OpenId连接。您可以直接添加它,或者通过获取
Microsoft.AspNetCore.Authentication.AzureAD.UI
软件包及以下内容

在这里,您可以逐个添加oidc作用域:

services.Configure(AzureADDefaults.OpenIdScheme,选项=>
{
options.Authority=options.Authority+“/v2.0/”;//Microsoft identity platform
options.TokenValidationParameters.ValidateIssuer=false;//接受多个租户
选项。范围。添加(“电子邮件”);
});

MicrosoftAccountOptions
默认包含
graph.microsoft.com/user.read
作用域,因此在完成流程后,您的
身份
应该拥有用户信息,而不需要任何附加技巧。但是,
AddMicrosoftAccount
实际上是带有特定预设的
AddOAuth
,可以被视为过时。由于这个原因,它不能为您提供
openid
范围

最新的替代方案是使用OpenId连接。您可以直接添加它,或者通过获取
Microsoft.AspNetCore.Authentication.AzureAD.UI
软件包及以下内容

在这里,您可以逐个添加oidc作用域:

services.Configure(AzureADDefaults.OpenIdScheme,选项=>
{
options.Authority=options.Authority+“/v2.0/”;//Microsoft identity platform
options.TokenValidationParameters.ValidateIssuer=false;//接受多个租户
选项。范围。添加(“电子邮件”);
});
我不知道如何请求额外的作用域,上面的内容不起作用,因为“profile”或“email”的声明从未返回

openid
email
profile
offline\u-access
都是
openid-Connect
范围。问题是
AddMicrosoftAccount
使用的是
OAuth 2.0
代码流,而不是OpenID Connect。这样示波器就不会工作了

使用
AddMicrosoftAccount
时,它会将范围设置为
https://graph.microsoft.com/user.read
默认情况下,这意味着它将获得一个访问令牌,在从Microsoft登录页重定向回应用程序后,您可以使用该令牌使用Microsoft Graph访问用户的基本信息,扩展将向Microsoft Graph endpoint()发送带有访问令牌的http post请求,以获取用户信息并创建身份验证票证,请参阅源代码

如果要使用
Openid Connect
,则应使用扩展名。如果你使用的是Azure广告,你最好使用Openid连接

我不知道如何请求额外的作用域,上面的内容不起作用,因为“profile”或“email”的声明从未返回

openid
email
profile
offline\u-access
都是
openid-Connect
范围。问题是
AddMicrosoftAccount
使用的是
OAuth 2.0
代码流,而不是OpenID Connect。这样示波器就不会工作了

使用
AddMicrosoftAccount
时,它会将范围设置为
https://graph.microsoft.com/user.read
默认情况下,这意味着它将获得一个访问令牌,在从Microsoft登录页重定向回应用程序后,您可以使用该令牌使用Microsoft Graph访问用户的基本信息,扩展将向Microsoft Graph endpoint()发送带有访问令牌的http post请求,以获取用户信息并创建身份验证票证,请参阅源代码


如果要使用
Openid Connect
,则应使用扩展名。如果您使用的是Azure AD,则最好使用Openid Connect。

尝试将每一个添加为对.Add()的单独调用。例如,添加(“openid”),.Add(“profile”)…尝试删除
范围。是否添加
<默认情况下,code>MicrosoftAccountOptions
包含范围。然后您必须查找
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
而不是简短的
电子邮件
显示名
等。这是一个非常古老的MS处理程序,(imo)为了向后兼容ws-fed和owinTry,将它们作为对.Add()的单独调用添加到Core中。例如,.Add(“openid”),.Add(“profile”)…尝试删除范围。是否添加?
MicrosoftAccountOptions
默认包含范围。然后您必须查找
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
而不是简短的
电子邮件
显示名称
等等。这是一个非常古老的MS处理程序,(imo)为了向后兼容ws-fed和owin而迁移到核心