gpt4 book ai didi

reactjs - 如何检索企业连接的可选声明(azure应用程序)

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

in this article它提到了如何向 azure 应用程序添加可选声明

所以我通过以下方式启用了family_namegiven_name

enter image description here

那么它如何在应用程序端检索这个?

在 auth0 示例应用程序中,它仅共享以下详细信息

enter image description here

import React from "react";
import { Container, Row, Col } from "reactstrap";

import Highlight from "../components/Highlight";
import Loading from "../components/Loading";
import { useAuth0, withAuthenticationRequired } from "@auth0/auth0-react";

export const ProfileComponent = () => {
const { user } = useAuth0();

return (
<Container className="mb-5">
<Row className="align-items-center profile-header mb-5 text-center text-md-left">
<Col md={2}>
<img
src={user.picture}
alt="Profile"
className="rounded-circle img-fluid profile-picture mb-3 mb-md-0"
/>
</Col>
<Col md>
<h2>{user.name}</h2>
<p className="lead text-muted">{user.email}</p>
</Col>
</Row>
<Row>
<Highlight>{JSON.stringify(user, null, 2)}</Highlight>
</Row>
</Container>
);
};

export default withAuthenticationRequired(ProfileComponent, {
onRedirecting: () => <Loading />,
});

最佳答案

我尝试通过 Postman 在我的环境中重现相同的结果,并得到以下结果:

我创建了一个 Azure AD 应用程序并分配了 API 权限,如下所示:

enter image description here

在 token 配置中,我添加了 family_namegiven_name,如下所示:

enter image description here

在生成访问 token 之前,请检查用户是否具有已更新这两个属性,如下所示:

enter image description here

为了获取访问 token 的代码,我使用了以下授权请求:

https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/authorize?
client_id=<application_id>
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=openid profile user.read
&state=12345

当我在浏览器中运行上述请求时,身份验证成功后,我在地址栏中收到了code,如下所示如下:

enter image description here

我使用以下参数通过 Postman 生成了访问 token :

POST https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token

client_id:<application_id>
grant_type:authorization_code
scope:openid profile user.read
client_secret:secret
redirect_uri:https://jwt.ms
code: code from above request

回应:

enter image description here

我在 jwt.ms 中解码了上述访问 token 并得到以下声明:

enter image description here

当我使用上述 token 通过此查询获取用户个人资料时,我同时获得了family_namegiven_name如下所示:

GET https://graph.microsoft.com/oidc/userinfo

回应:

enter image description here

就您的情况而言,请确保登录用户是否同时具有family_name< strong>given_name 属性是否在其个人资料中更新。

请通过解码来检查访问 token 是否包含 family_namegiven_name 声明。

关于reactjs - 如何检索企业连接的可选声明(azure应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74259029/

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