adal.js用于不同的后端

时间:2015-03-09 12:37:20

标签: javascript azure-active-directory adal

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

例如:我的网络应用程序位于http://localhosthost:8080/ui/          以及http://localhosthost:8080/rest-api/

上的Web 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
        );

}]);

2 个答案:

答案 0 :(得分:0)

如果您只处理单个AAD服务器进行身份验证,则需要将API网址映射到客户端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是否将身份验证标头附加到请求,以及使用哪个承载令牌。

答案 1 :(得分:-1)

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

ADAL.js比较端点以附加CORS api调用的令牌。

您的服务端点网址可能与指定的端点不同。您可以在adal-angular.js

中看到ProtectedResourceInterceptor中的令牌附件逻辑