【发布时间】:2020-07-24 22:41:11
【问题描述】:
我正在使用 react-aad-masl 模块将 Microsoft SSO 集成到我的 react 应用程序中。我可以将我的用户重定向到 Microsoft 登录页面,然后它会带着令牌返回我的页面。之后它只返回包含用户名和电子邮件 ID 的 accountInfo。我需要获取用户的其他详细信息以及 ID、名字、姓氏、组等。
这些所有细节都将通过此 Azure AD MASL 获得,还是我需要调用 Graph API?
下面是我的实现
//authProvider.js
import { MsalAuthProvider, LoginType } from 'react-aad-msal';
import { Logger, LogLevel } from "msal";
// Msal Configurations
const config = {
auth: {
authority: 'https://login.microsoftonline.com/*********',
clientId: '*************',
redirectUri: 'http://localhost:3000/'
},
// Enable logging of MSAL events for easier troubleshooting.
// This should be disabled in production builds.
system: {
logger: new Logger(
(logLevel, message, containsPii) => {
console.log("[MSAL]", message);
},
{
level: LogLevel.Verbose,
piiLoggingEnabled: false
}
)
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: true
}
};
// Authentication Parameters
const authenticationParameters = {
scopes: [
'user.read',
'profile',
'openid'
//'profile.read',
// 'User.Read.All',
// 'Group.Read.All',
// 'User.ReadBasic.All',
// 'Group.Read'
]
}
// Options
const options = {
loginType: LoginType.Redirect,
tokenRefreshUri: window.location.origin + '/auth.html'
}
export const authProvider = new MsalAuthProvider(config, authenticationParameters, options)
//APP.js
<AzureAD provider={authProvider} forceLogin={false}>
{(abc) => {
console.log('>>>>>>>>>>>>...', abc);
props.setAccountInfo(abc.accountInfo.account);
return <AppRouter />
}}
</AzureAD>
在 abc 我得到以下信息
请帮帮我
【问题讨论】:
标签: reactjs azure-active-directory microsoft-graph-api