2017-03-17 22 views
1

我有一個角度(1.x)SPA,並試圖通過ADAL來保護它,以通過Azure AD需要身份驗證。 但是,即使是標有requireADLogin: true的路由/頁面/狀態似乎也允許用戶訪問它們而不需要授權。ADAL requireADLogin和angular-ui-router?

我不知道是否問題是我使用angular-ui-router(0.4.2)而不是ngRoute,因此我沒有真正考慮到我對路由/狀態的配置。

我的HTML模板顯示userInfo並在這{"isAuthenticated":false,"userName":"","loginError":""}第一次加載,但頁面加載(包括孩子的路線/狀態),即使我在外殼和/或子狀態設置requireADLogin: true(見下文)。

我有一個登錄按鈕導致登錄順序在彈出窗口中,當完成時,頁面顯示登錄用戶的userInfo, ,所以我想我讓其他人排隊了。 v

// My top-level app config block: 
function AppConfig($stateProvider, $urlRouterProvider, $httpProvider, adalAuthenticationServiceProvider) { 

    // Configure the urlRouteProvider to redirect to /intro by default 
    $urlRouterProvider.otherwise("/intro"); 

    // Configure the ADAL Auth Provider 
    adalAuthenticationServiceProvider.init({ 
     tenant: "[MyTenantID]", 
     clientId: "[MyClientID]", 
     popUp: true 
    } 
    // // pass http provider to inject request interceptor to attach tokens 
    // $httpProvider 
    ); 
} 

// Later I set up my shell state/route (all other states are children of this one): 
$stateProvider.state('shell', { 
    //blank url as the shell is an abstract parent to every other state 
    url: '', 
    templateUrl: 'app/shell/shell.html', 
    controller: 'ShellController', 
    controllerAs: 'vm', 
    abstract: true, 
    requireADLogin: false // <-- tried with requireADLogin: true 
}); 

// Intro (aka shell.intro) should be the default state: 
$stateProvider.state('shell.intro', { 
    url: '/intro', 
    templateUrl: 'app/intro/intro.html', 
    controller: 'IntroController', 
    controllerAs: 'vm', 
    data: { 
     pageTitle: 'Intro' 
    }, 
    requireADLogin: true 
}); 

回答

1

我有一個快速的測試與您的代碼段,並找到主要的犯罪可能是下adalAuthenticationServiceProvider.init功能評論了一句$httpProvider的操作。

請去掉這一判決,原因也是在https://github.com/AzureAD/azure-activedirectory-library-for-js#getting-started提供的代碼示例:

$httpProvider // pass http provider to inject request interceptor to attach tokens

這將解決您就在我身邊的問題,請試試吧。

+0

生病 - 會盡快完成並更新。感謝您的時間! – FOR

+0

取消註釋$ httpProvider行似乎已經完成了這個訣竅 - 謝謝! – FOR