1

我正在尝试在下面的链接中实现类似的东西。有人可以让我知道如何使用此令牌访问安全的第三方 API。

例如:我的 Web 应用位于http://localhosthost:8080/ui/ ,Web API 位于http://localhosthost:8080/rest-api/

我仍然没有看到请求附带任何令牌。

这是我的代码

 app.config(['$routeProvider', '$httpProvider', 'adalAuthenticationServiceProvider', function ($routeProvider, $httpProvider,    
adalAuthenticationServiceProvider) {
 $routeProvider
 .when("/", {templateUrl: "partials/package.html", requireADLogin: true,})
  .when("/dashboard", {templateUrl: "partials/package.html", controller: "searchCtrl", requireADLogin: true,})
  .when("/create", {templateUrl: "partials/upload.html", controller: "packageCtrl", requireADLogin: true,})
   $routeProvider.otherwise({ redirectTo: "/home" });

var endpoints = {
    // Map the location of a request to an API to a the identifier of the associated resource
    "http://localhost:8081/rest-api/":
        "http://localhost:8081/rest-api/",
};
  adalAuthenticationServiceProvider.init(
        {
        tenant: 'common',
        clientId: '',
           extraQueryParameter: 'nux=1',
        endpoints: endpoints
        },
        $httpProvider
        );

}]);

4

2 回答 2

0

如果您只处理单个 AAD 服务器进行身份验证,则需要将 API url 映射到客户端 id 令牌:

var clientId = 'some guid';
var endpoints = {
        "http://localhost:8081/rest-api/": clientId,
    };

 adalAuthenticationServiceProvider.init(
        {
        tenant: 'common',
        clientId: clientId,
        extraQueryParameter: 'nux=1',
        endpoints: endpoints
        },
        $httpProvider
        );

这告诉 ADAL 针对与属性名称匹配的 URL 的 HTTP 请求,使用存储在右侧键下的不记名令牌。

我建议查看 ADAL 函数 getResourceForEndpoint(从 v1.0.14 开始) - 此函数输出确定 ADAL-angular 是否将身份验证标头附加到请求,以及使用哪个承载令牌。

于 2017-05-08T21:08:23.243 回答
-1

端点用于不同主机上的 CORS api 请求。您可以在此处查看示例https://github.com/AzureADSamples/SinglePageApp-WebAPI-AngularJS-DotNet

ADAL.js 将端点与 CORS api 调用的附加令牌进行比较。

您的服务端点 url 可能与指定的端点不同。您可以在 adal-angular.js 中看到 ProtectedResourceInterceptor 中的令牌附加逻辑

于 2015-03-09T19:06:38.770 回答