gpt4 book ai didi

azure - 如何从 Microsoft Azure AD 登录过程获取用户主体名称

转载 作者:行者123 更新时间:2023-12-02 06:15:57 25 4
gpt4 key购买 nike

我正在使用 @azure/msal-angular 登录用户。我提供了以下“同意范围”:

['openid', 'email', 'profile']

登录重定向过程有效,因为它将我重定向到“https://login.microsoftonline.com ” URL,并且“scope”参数如下所示:

&scope=email%20openid%20profile

到目前为止一切顺利,我登录,重定向回我的网站,然后打印出 MSAL 服务提供的“getUser()”方法(在敏感值的情况下进行混淆):

displayableId: "D...Mm"
name: "Mo....as"
identityProvider: "htt...0"
userIdentifier: "OG....5"
idToken:
aud: "ca...20"
iss: "htt....0"
iat: 1..83
nbf: 15..83
exp: 15...83
acct: 0
aio: "42dg....R/XQoA"
auth_time: 159...282
email: "DM.....com"
name: "Mo....as"
nonce: "7bc....d95d"
oid: "8e8f....fc3"
platf: "1"
preferred_username: "DMol....om"
sub: "j0KKHsU....WMEB_H3fyU"
tid: "98f7abd.....6fbd5f9"
uti: "Eu4y.....cMAAA"
ver: "2.0"

此处未提供 UPN 值。经过研究,我发现1.0版本默认返回UPN。

我发现这个有用的问题,包含大量信息,但它实际上并没有回答问题:

https://stackoverflow.com/a/57692622/1079602

以下是 Microsoft 文档 ( https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-optional-claims ) 的屏幕截图

Microsoft doc image

它特别指出“profile”范围应返回“upn”值。我不认为这是 @azure/msal-angular 包的问题,​​因为登录 URL 已正确生成。

最佳答案

您得到的是id token ,它不包括upn声明,请参阅 doc .

upn声明将包含在访问 token 中,要获取访问 token ,您可以引用示例here ,它使用 Implicit grant flow .

// app.module.ts
@NgModule({
declarations: [
// ...
],
imports: [
// ...
MsalModule.forRoot({
auth: {
clientId: 'Enter_the_Application_Id_Here',
}
},
{
popUp: !isIE,
consentScopes: [
'user.read',
'openid',
'profile',
],
protectedResourceMap: [
['https://graph.microsoft.com/v1.0/me', ['user.read']]
]
})
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule { }

当您使用此流程获取访问 token 时,您会发现 token 是 ver: "1.0",因为 token 的版本由资源决定(在您的情况下,Microsoft图),不是客户端,引用原因here :

enter image description here


测试:

https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/authorize?
client_id=xxxxx
&response_type=token
&redirect_uri=http://localhost/myapp/permissions
&scope=email openid profile
&response_mode=fragment
&state=12345
&nonce=678910

enter image description here

关于azure - 如何从 Microsoft Azure AD 登录过程获取用户主体名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62027576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com