Hon*_*iao 5 javascript azure-active-directory hello.js microsoft-graph-api
我正在使用 hello.js 登录 Microsoft Graph。
首先我初始化
hello.init({
msft: {
id: myAppId,
oauth: {
version: 2,
auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
},
scope_delim: ' ',
form: false
},
},
{ redirect_uri: window.location.href }
);
Run Code Online (Sandbox Code Playgroud)
然后我在我的应用程序中成功登录
hello('msft').login({ scope: 'User.Read' })
Run Code Online (Sandbox Code Playgroud)
这是登录后hello.js保存在localStorage中的内容。
{
"msft": {
"access_token":"aLongToken",
"token_type":"Bearer",
"expires_in":3599,
"scope":"basic,User.Read",
"state":"",
"session_state":"f034f785-f8d0-4cec-aab4-88559c9d93dd",
"client_id":"a91e6907-2b6e-4793-848d-633e960e809d",
"network":"msft",
"display":"popup",
"redirect_uri":"http://localhost:3006/login",
"expires":1501800737.361
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试刷新 access_token
hello('msft').login({
display: 'none',
response_type: 'id_token token',
response_mode: 'fragment',
nonce: 'my-app',
prompt: 'none',
scope: 'User.Read',
login_hint: 'Rose.Bukater@company.com',
domain_hint: 'organizations'
})
Run Code Online (Sandbox Code Playgroud)
我得到了错误
AADSTS50058:发送了无提示登录请求,但没有用户登录。用于表示用户会话的 cookie 未在请求中发送到 Azure AD。如果用户使用 Internet Explorer 或 Edge,并且发送静默登录请求的 Web 应用与 Azure AD 终结点 (login.microsoftonline.com) 位于不同的 IE 安全区域,则可能会发生这种情况。
我正在使用 Chrome。
在 GitHub 上发现了这个问题。但仍然没有弄清楚如何正确刷新。
更新:
在https://apps.dev.microsoft.com禁用允许隐式流后,现在我什至无法登录。所以这不是正确的解决方案。hello.js 在 localStorage 中保存了这个错误:
{
"msft": {
"error": {
"code":"unsupported_response_type",
"message":"AADSTS70005: response_type 'token' is not enabled for the application\r\nTrace ID: 1dc20dd0-cab3-41b5-9849-2a7e35d60700\r\nCorrelation ID: caacce8f-6763-405d-a840-70c24d5306d4\r\nTimestamp: 2017-08-04 21:56:42Z"
},
"error_description":"AADSTS70005: response_type 'token' is not enabled for the application\r\nTrace ID: 1dc20dd0-cab3-41b5-9849-2a7e35d60700\r\nCorrelation ID: caacce8f-6763-405d-a840-70c24d5306d4\r\nTimestamp: 2017-08-04 21:56:42Z",
"state":"",
"client_id":"a91e6907-2b6e-4793-848d-633e960e809d",
"network":"msft",
"display":"popup",
"redirect_uri":"http://localhost:3006/login",
"scope":"basic,User.Read"
}
}
Run Code Online (Sandbox Code Playgroud)
我发现了这个问题。我在问题中的代码是完全正确的。造成这个问题的原因是因为在我们公司每个人都有两封电子邮件:
userPrincipalName对于login_hint下面的情况,它必须是别名电子邮件。
hello('msft').login({
display: 'none',
response_type: 'id_token token',
response_mode: 'fragment',
nonce: 'my-app',
prompt: 'none',
scope: 'User.Read',
login_hint: 'Rose.Bukater@company.com', // <- has to be rosebuk@company.com
domain_hint: 'organizations'
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17983 次 |
| 最近记录: |