访问被拒绝。检查凭据并重试
•浏览 1
Access is denied. Check credentials and try again
我正在尝试按照此权限指南在 node.js 上使用 Microsoft Graph API (https://graph.microsoft.com/v1.0/me/calendarView) 访问日历事件,但我收到错误响应:
{
"code":"ErrorAccessDenied",
"message":"Access is denied. Check credentials and try again.",
"innerError": {
"request-id":"7c2...",
"date":"2016-07-13T21:19:11"
}
}request({url : 'https://graph.microsoft.com/v1.0/me/calendarview', qs : queryParams, 'auth': {'bearer': token}}, function (error, response, body) {
...
});request({url : 'https://graph.microsoft.com/v1.0/me/', 'auth': {'bearer': token}}, function (error, response, body) {
...
});{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"id":"<valid_id>",
"businessPhones":[],
"displayName":"<valid_name>",
"givenName":"<valid_name>",
"jobTitle":"<valid_title>",
"mail":"<valid_email>",
"mobilePhone":"<valid_cell>",
"officeLocation":null,
"preferredLanguage":"en-US",
"surname":"<valid_name>",
"userPrincipalName":"<valid_email>"}var AzureOAuthStrategy = require('passport-azure-oauth').Strategy;
passport.use(new AzureOAuthStrategy({
clientId: config.live.clientID,
clientSecret: config.live.clientSecret,
tenantId: config.live.tenant,
resource: 'https://graph.microsoft.com/',
redirectURL: config.live.callbackURL
},
function(accessToken, refreshToken, profile, done) {
调用是使用 :
{
"code":"ErrorAccessDenied",
"message":"Access is denied. Check credentials and try again.",
"innerError": {
"request-id":"7c2...",
"date":"2016-07-13T21:19:11"
}
}request({url : 'https://graph.microsoft.com/v1.0/me/calendarview', qs : queryParams, 'auth': {'bearer': token}}, function (error, response, body) {
...
});request({url : 'https://graph.microsoft.com/v1.0/me/', 'auth': {'bearer': token}}, function (error, response, body) {
...
});{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"id":"<valid_id>",
"businessPhones":[],
"displayName":"<valid_name>",
"givenName":"<valid_name>",
"jobTitle":"<valid_title>",
"mail":"<valid_email>",
"mobilePhone":"<valid_cell>",
"officeLocation":null,
"preferredLanguage":"en-US",
"surname":"<valid_name>",
"userPrincipalName":"<valid_email>"}var AzureOAuthStrategy = require('passport-azure-oauth').Strategy;
passport.use(new AzureOAuthStrategy({
clientId: config.live.clientID,
clientSecret: config.live.clientSecret,
tenantId: config.live.tenant,
resource: 'https://graph.microsoft.com/',
redirectURL: config.live.callbackURL
},
function(accessToken, refreshToken, profile, done) {
请求有一个有效的令牌,并且通过
调用 .../me/
{
"code":"ErrorAccessDenied",
"message":"Access is denied. Check credentials and try again.",
"innerError": {
"request-id":"7c2...",
"date":"2016-07-13T21:19:11"
}
}request({url : 'https://graph.microsoft.com/v1.0/me/calendarview', qs : queryParams, 'auth': {'bearer': token}}, function (error, response, body) {
...
});request({url : 'https://graph.microsoft.com/v1.0/me/', 'auth': {'bearer': token}}, function (error, response, body) {
...
});{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"id":"<valid_id>",
"businessPhones":[],
"displayName":"<valid_name>",
"givenName":"<valid_name>",
"jobTitle":"<valid_title>",
"mail":"<valid_email>",
"mobilePhone":"<valid_cell>",
"officeLocation":null,
"preferredLanguage":"en-US",
"surname":"<valid_name>",
"userPrincipalName":"<valid_email>"}var AzureOAuthStrategy = require('passport-azure-oauth').Strategy;
passport.use(new AzureOAuthStrategy({
clientId: config.live.clientID,
clientSecret: config.live.clientSecret,
tenantId: config.live.tenant,
resource: 'https://graph.microsoft.com/',
redirectURL: config.live.callbackURL
},
function(accessToken, refreshToken, profile, done) {
返回:
{
"code":"ErrorAccessDenied",
"message":"Access is denied. Check credentials and try again.",
"innerError": {
"request-id":"7c2...",
"date":"2016-07-13T21:19:11"
}
}request({url : 'https://graph.microsoft.com/v1.0/me/calendarview', qs : queryParams, 'auth': {'bearer': token}}, function (error, response, body) {
...
});request({url : 'https://graph.microsoft.com/v1.0/me/', 'auth': {'bearer': token}}, function (error, response, body) {
...
});{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"id":"<valid_id>",
"businessPhones":[],
"displayName":"<valid_name>",
"givenName":"<valid_name>",
"jobTitle":"<valid_title>",
"mail":"<valid_email>",
"mobilePhone":"<valid_cell>",
"officeLocation":null,
"preferredLanguage":"en-US",
"surname":"<valid_name>",
"userPrincipalName":"<valid_email>"}var AzureOAuthStrategy = require('passport-azure-oauth').Strategy;
passport.use(new AzureOAuthStrategy({
clientId: config.live.clientID,
clientSecret: config.live.clientSecret,
tenantId: config.live.tenant,
resource: 'https://graph.microsoft.com/',
redirectURL: config.live.callbackURL
},
function(accessToken, refreshToken, profile, done) {
所以我假设这是在 https://manage.windowsazure.com/ 上设置权限的问题,我在其中创建了两个应用程序,一个用于节点服务器,一个用于 Web 客户端应用程序。我正在使用护照进行身份验证,并使用 Web 客户端应用程序的客户端 ID 和密码。
{
"code":"ErrorAccessDenied",
"message":"Access is denied. Check credentials and try again.",
"innerError": {
"request-id":"7c2...",
"date":"2016-07-13T21:19:11"
}
}request({url : 'https://graph.microsoft.com/v1.0/me/calendarview', qs : queryParams, 'auth': {'bearer': token}}, function (error, response, body) {
...
});request({url : 'https://graph.microsoft.com/v1.0/me/', 'auth': {'bearer': token}}, function (error, response, body) {
...
});{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"id":"<valid_id>",
"businessPhones":[],
"displayName":"<valid_name>",
"givenName":"<valid_name>",
"jobTitle":"<valid_title>",
"mail":"<valid_email>",
"mobilePhone":"<valid_cell>",
"officeLocation":null,
"preferredLanguage":"en-US",
"surname":"<valid_name>",
"userPrincipalName":"<valid_email>"}var AzureOAuthStrategy = require('passport-azure-oauth').Strategy;
passport.use(new AzureOAuthStrategy({
clientId: config.live.clientID,
clientSecret: config.live.clientSecret,
tenantId: config.live.tenant,
resource: 'https://graph.microsoft.com/',
redirectURL: config.live.callbackURL
},
function(accessToken, refreshToken, profile, done) {
这是我在节点应用程序上为"其他应用程序的权限"设置的:
- Windows Azure 活动目录:
- 委托权限
- 阅读所有用户的完整个人资料
- 登录并阅读用户资料
- 委托权限
- 微软图表:
- 委托权限
- 拥有对用户日历的完全访问权限
- 阅读用户日历
- 委托权限
- (见下文)
- 委托权限
- 使用权
- 委托权限
这是我在 Web 客户端应用程序上为"其他应用程序的权限"设置的内容:
- 微软图形:
- 申请权限
- 在所有邮箱中读取和写入日历
- 阅读所有邮箱中的日历
- 委托权限
- 登录用户
- 读取用户联系人
- 拥有对用户日历的完全访问权限
- 阅读用户日历
- 登录并阅读用户资料
- 申请权限
- Office Exchange 360?? 在线版:
- 申请权限
- 在所有邮箱中读取和写入日历
- 阅读所有邮箱中的日历
- 委托权限
- 读取用户和共享日历
- 读写用户和共享日历
- 阅读所有用户的基本资料
- 阅读用户资料
- 读取用户联系人
- 阅读用户日历
- 申请权限
- Windows Azure 活动目录
- 申请权限:无
- 委托权限
- 登录并阅读用户资料
我不是 100% 了解 Azure 管理门户中设置的权限与特定端点访问之间的关系。我已阅读 API 范围文章,但该文章中的讨论对于我的需求来说有点过于概念化。
最终,我试图访问租户 ID 内的所有可预留资源并将事件写入事件。
我能够通过删除然后通过 https://manage.windowsazure.com/ 重新生成应用程序然后更新客户端 ID 和密码来解决问题。事实上,我能够从应用程序列表中删除本机客户端(节点)应用程序,并且仍然可以进行调用。
虽然我没有使用飞雪提供的参考 https://jwt.io/,但我认为它对于将来调试 azure to API 权限将非常有用。