我是 Office 365 的新手,在访问 rest api 时遇到问题。我正在尝试测试Calendar 和 Mail API的其余 api ,所以我决定使用 Postman。但是,为了测试这些 API,我需要 Authorization 标头中的访问令牌。为了弄清楚如何获取令牌,我决定在这里获取示例项目,在此本地站点上配置、运行和登录,以获取缓存在本地存储中的令牌,并将该令牌用于 Postman 中的进一步请求。但是,我测试的所有请求都返回了“401 未经授权的请求”。
我做了什么:
- 在与 O365 帐户关联的 Azure ADD 上注册新应用
- 添加完整的应用权限和委派权限。
- 在清单文件中将“oauth2AllowImplicitFlow”更新为 true。
- 克隆示例项目
在 app.js 中,我将更改配置功能的内容如下
function config($routeProvider, $httpProvider, adalAuthenticationServiceProvider) { $routeProvider .when('/', { templateUrl: 'views/home.html', controller: 'HomeController', controllerAs: 'home', requireADLogin: true }) .otherwise({ redirectTo: '/' }); // The endpoints here are resources for ADAL to get tokens for. var endpoints = { 'https://outlook.office365.com': 'https://outlook.office365.com' }; // Initialize the ADAL provider with your tenant name and clientID (found in the Azure Management Portal). adalAuthenticationServiceProvider.init( { tenant: 'mytenantname.onmicrosoft.com', clientId: '<my cliend Id>', endpoints: endpoints, cacheLocation: 'localStorage' }, $httpProvider ); };
然后我运行了应用程序,它让我登录很好,我也可以获得令牌,但该令牌也未经授权请求。我解码了令牌并看到了“aud”的值,它没有返回“ https://outlook.office365.com/ ”。在这个 url中,作者说“这应该是” https://outlook.office365.com/ “用于邮件、日历或联系人 API”
那么我错过了什么?