1

Office365 세입자의 모든 사용자와 함께 드롭 다운을 만들려고합니다. Azure AD에서 앱을 만들고 필요한 모든 권한을주었습니다. 나는 사실, 애플 리케이션 및 위임 Microsoft Graph에 대한 모든 권한을 주었다. 모두들.비 관리자 용 Microsoft Graph API 사용 권한?

그런 다음 모든 사용자에게 https://graph.microsoft.com/v1.0/users을 쿼리하는 스크립트를 작성했습니다.

필자는 세입자 관리자가 권한을 받아 UI의 사용자 목록을 출력하도록했습니다. 내가 관리자 모르겠지만 관리자

을 위해 잘 작동 나는 다음과 같은 오류 페이지로 이동하는 경우 :

나는이 더 낮은 권한을 가진 사용자를 위해 작동하는지 알 필요가

This application requires application permissions to another application. Consent for application permissions can only be performed by an administrator. Sign out and sign in as an administrator or contact one of your organization's administrators.

. 내가 API 요청을 이해하고 Azure에서 응용 프로그램에 부여 된 권한으로 응용 프로그램이 실행 중입니다. 따라서 사용자가 읽기 전용으로되어 있어도 사용자가 요청을 실행하지 않아도 설정 한 응용 프로그램에서 실행됩니다. 그렇다면 권한과 관련하여 오류가 발생하는 이유는 무엇입니까? 마이크로 소프트 그래프 허가/범위의 두 종류가 있습니다

(function() { 
    "use strict"; 
    // Some samples will use the tenant name here like "tenant.onmicrosoft.com" 
    // I prefer to user the subscription Id 
    var subscriptionId = "metenant.onmicrosoft.com"; 
    // Copy the client ID of your AAD app here once you have registered one, configured the required permissions, and 
    // allowed implicit flow https://msdn.microsoft.com/en-us/office/office365/howto/get-started-with-office-365-unified-api 
    var clientId = "cccb1f2f-xxx-x-xxxxx-x-x-x-x-x-"; 

    window.config = { 
    // subscriptionId: subscriptionId, 
    clientId: clientId, 
    postLogoutRedirectUri: window.location.origin, 
    endpoints: { 
     graphApiUri: 'https://graph.microsoft.com' 
    }, 
    cacheLocation: 'localStorage' // enable this for IE, as sessionStorage does not work for localhost. 
    }; 

    var authContext = new AuthenticationContext(config); 

    // Check For & Handle Redirect From AAD After Login 
    var isCallback = authContext.isCallback(window.location.hash); 
    authContext.handleWindowCallback(); 

    if (isCallback && !authContext.getLoginError()) { 
    window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST); 
    } 

    // If not logged in force login 
    var user = authContext.getCachedUser(); 
    // NOTE: you may want to render the page for anonymous users and render 
    // a login button which runs the login function upon click. 
    if (!user) authContext.login(); 

    // Acquire token for Files resource. 
    authContext.acquireToken(config.endpoints.graphApiUri, function (error, token) { 
    // Handle ADAL Errors. 
    if (error || !token) { 
     console.log('ADAL error occurred: ' + error); 
     return; 
    } 
    // Execute GET request to Files API. 
    var filesUri = config.endpoints.graphApiUri + "/v1.0/users"; 
    $.ajax({ 
     type: "GET", 
     url: filesUri, 
     headers: { 
     'Authorization': 'Bearer ' + token, 
     } 
    }).done(function (response) { 
     console.log('Successfully fetched from Graph.'); 
     console.log(response); 

     var container = $(".container") 

     container.empty(); 

     $.each(response.value, function(index, item) { 
     container.append($('<li>').text(item.displayName + " " + item.mail + " " + item.mobilePhone)) 
     }) 
    }).fail(function (response) { 
     var err = JSON.parse(response.responseText) 
     console.log('Failed:', err.error.message); 
    }); 
    }); 
})(); 
+0

현재 로그인 한 사용자의 토큰을 Graph API에 전달하는 것처럼 보입니다. 임차인의 서비스 주체에 적절한 권한을 부여한 다음 서비스 주체 토큰을 획득하고이를 Graph 호출에 사용할 수 있습니다. – Aram

+0

ADAL을 사용하고 있고 앱의 clientID가 그래프 API에 대한 앱 로그인에서 전달되고 현재 사용자가 아니라면 지나치지 않아야합니까? 내가 이것을 사용하기 위해 사용하는 코드를 추가했습니다. – Batman

답변

1

:

내가 사용하고 코드입니다. 하나는 관리자의 동의가 필요하다는 것입니다. 다른 하나는 필요하지 않습니다.

이 앱에 대해 설정 한 권한은 무엇입니까? 당신은 here에서 허가/범위에 대한 자세한 정보를 얻을 수 있습니다 enter image description here

: 관리자의 동의없이 사용자를 나열하려면, 우리는 아래 그림처럼 User.ReadBasic.All 범위를 사용할 수 있습니다.

수정 : 현재

의 adal.js는 관리자의 동의를 제공하지 않습니다.

AuthenticationContext.prototype.login = function (prompt) { 
// Token is not present and user needs to login 
var expectedState = this._guid(); 
this.config.state = expectedState; 
this._idTokenNonce = this._guid(); 
this._logstatus('Expected state: ' + expectedState + ' startPage:' + window.location); 
this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST, window.location); 
this._saveItem(this.CONSTANTS.STORAGE.LOGIN_ERROR, ''); 
this._saveItem(this.CONSTANTS.STORAGE.STATE_LOGIN, expectedState); 
this._saveItem(this.CONSTANTS.STORAGE.NONCE_IDTOKEN, this._idTokenNonce); 
this._saveItem(this.CONSTANTS.STORAGE.FAILED_RENEW, ''); 
this._saveItem(this.CONSTANTS.STORAGE.ERROR, ''); 
this._saveItem(this.CONSTANTS.STORAGE.ERROR_DESCRIPTION, ''); 


var urlNavigate = this._getNavigateUrl('id_token', null) + '&nonce=' + encodeURIComponent(this._idTokenNonce); 

if (prompt && prompt === "admin_consent") { 
    urlNavigate = urlNavigate + "&prompt=admin_consent" 
} 


this.frameCallInProgress = false; 
this._loginInProgress = true; 
if (this.config.displayCall) { 
    // User defined way of handling the navigation 
    this.config.displayCall(urlNavigate); 
} else { 
    this.promptUser(urlNavigate); 
} 
// callback from redirected page will receive fragment. It needs to call oauth2Callback 
}; 

을 그리고 당신은 각도를 사용한다면, 우리는 또한 ADAL-angular.js 수정해야합니다 :이 기능을 사용하려면 다음과 같은 prameter를 추가하는 코드를 수정할 수 있습니다

this.$get = ['$rootScope', '$window', '$q', '$location', '$timeout', function ($rootScope, $window, $q, $location, $timeout) { 
... 
return { 
       // public methods will be here that are accessible from Controller 
       config: _adal.config, 
       login: function (prompt) { 
       _adal.login(prompt); 
     }, 
... 
} 

그러면 사용자 로그인을위한 두 개의 버튼을 제공 할 수 있습니다. 하나의 버튼은 사용자 로그인을위한 버튼입니다. 그리고 다른 하나는 관리자가 조직에 대한 동의를하는 것입니다. 다음은 각도 제어에서 관리자 동의를위한 로그인 페이지로 리디렉션하는 코드입니다.

$scope.login = function() { 
    adalService.login("admin_consent"); 
}; 
+0

API 요청이 사용자 컨텍스트가 아닌 앱 컨텍스트에서 실행 중이라는 인상 때문에 모든 권한을 부여하고있었습니다. 내가 틀렸던 것 같습니다. ADAL을 통해 전송 된 토큰은 사용자 권한을 반영합니다. 그래서 앱이 관리자 권한을 필요로하는 권한을 가지고 있기 때문에 사용자가 관리자가되어야하기 때문에 실패한 것입니다. 관리자 권한이 아닌 사용 권한 만 부여하면 올바르게 작동합니다. – Batman

+0

또한 ADAL이 실행되는 페이지에 사용자가 로그인 할 때마다 앱을 수락 할 것을 요청합니다. 하지만 관리자가 응용 프로그램을 승인하면 그렇게 행동하지 않을 것이라고 생각했습니다. 어떤 아이디어? – Batman

+0

토큰의 사용 권한은 획득 한 흐름에 따라 다릅니다. 클라이언트 신임 정보의 경우 토큰은 사용자가 로그인하지 않은 상태에서 앱 권한을 위임합니다. 귀하의 시나리오에서 토큰은 사용자가 앱에 동의 할 수있는 충분한 권한을 요구하는 delegate-token입니다. 두 번째 문제의 경우 관리자가 조직의 응용 프로그램을 승인하도록하려면 처음 요청시이를 명시 적으로 지정해야합니다. 이를 달성하려면 ** prompt = admin_consent ** 매개 변수를 추가해야합니다. –