최근까지만 MS Graph API 권한이 필요한 AAD 응용 프로그램이 있습니다. 이제 MS Graph API와 AAD API 권한이 필요합니다. 응용 프로그램에는 사용자가 언제 다시 동의해야하는지 결정하는 프로세스가 있습니다. AAD API 권한을 추가하기 전에 재 승인 프로세스는 범위를 얻기 위해 MS Graph API 액세스 토큰을 구문 분석하여 재 승인이 필요한지 여부를 판별합니다. 그런 다음 해당 범위를 응용 프로그램에 포함 된 정적 목록과 비교합니다. 필요한 액세스 권한 중 하나가 액세스 토큰의 범위에 포함되지 않은 경우 사용자가 다시 동의하기 위해 동의 페이지로 리디렉션되었습니다. AAD API 권한을 추가하면 해당 AAD 자원을 사용하여 응용 프로그램이 요청하고 AAD API 액세스 토큰을 요청합니다. 그러나 두 API와 관련된 범위가 MS Graph 액세스 토큰과 AAD 액세스 토큰 모두에 포함되어있는 것으로 보입니다.액세스 토큰 내의 두 가지 다른 API에 대해 결합 된 범위보기
코드 액세스 토큰을 얻을 수 있습니다 :
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthorizationCodeReceived = async (context) =>
{
var code = context.Code;
// retriever caller data from the incoming principal
string claimClientId = Claim.Value(context.AuthenticationTicket.Identity.Claims, Claim.Type.ClientId);
string upn = Claim.Value(context.AuthenticationTicket.Identity.Claims, ClaimTypes.Name);
string officeTenantId = Claim.Value(context.AuthenticationTicket.Identity.Claims, Claim.Type.OfficeTenantId, upn);
//Obtain MS Graph API Access Token
Credential = new ClientCredential(ClientId, AppKey);
var signedInUserId = Claim.Value(context.AuthenticationTicket.Identity.Claims, ClaimTypes.NameIdentifier);
AuthenticationContext authContext = new AuthenticationContext($"{LoginEndpoint}/{officeTenantId}", new RedisTokenCache(signedInUserId));
AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), Credential, GraphResourceId);
//Obtain AAD Graph API Access Token
AuthenticationResult aadResult = await authContext.AcquireTokenByAuthorizationCodeAsync(code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), Credential, AadGraphResourceId);
…
범위를 내가 다시 받고 있어요 :
- 자원 = graph.windows.net, 스코프 = Directory.AccessAsUser.All Directory.ReadWrite. 모든 Files.ReadWrite.All, Group.ReadWrite.All, 프로필, User.Read
- 자원 = graph.microsoft.com, 스코프 = Directory.AccessAsUser.All, Directory.ReadWrite.All, Files.ReadWrite.All, 그룹 .ReadWrite.All, profile, User.Read ,451,515,
스코프 내가 기대 해요 :
- 자원 = graph.windows.net, 스코프 = Directory.AccessAsUser.All, User.Read
- 자원 = graph.microsoft.com, 스코프 = 디렉토리 두 자원이 모든 API를 사용자와 관련된 범위를 얻을 것 같습니다 제가보고 있어요 바탕으로 .ReadWrite.All, Files.ReadWrite.All, Group.ReadWrite.All, 프로필, User.Read
동의했다. 이 예상되는 동작입니까? 각 리소스별로 별도의 범위 목록을 얻으려면 어떻게해야합니까?
여기에 MS 그래프 탐색기, AAD 그래프 Explorer 및 JWT 디코더에서 일부 출력입니다 :
//Service Principal for my test app
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/Microsoft.DirectoryServices.ServicePrincipal/@Element",
"odata.type": "Microsoft.DirectoryServices.ServicePrincipal",
"objectType": "ServicePrincipal",
"objectId": "2f9f4cf5-7576-42c9-8f9d-c1c3e6e63b4d",
"appDisplayName": "My Test App",
}
//Service Principal for MS Graph API
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/Microsoft.DirectoryServices.ServicePrincipal/@Element",
"odata.type": "Microsoft.DirectoryServices.ServicePrincipal",
"objectType": "ServicePrincipal",
"objectId": "4036b7c7-c9b0-447f-a5d8-18794d0d2a23",
"appDisplayName": "Microsoft Graph",
"appId": "00000003-0000-0000-c000-000000000000",
}
//Service Principal for AAD API
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/Microsoft.DirectoryServices.ServicePrincipal/@Element",
"odata.type": "Microsoft.DirectoryServices.ServicePrincipal",
"objectType": "ServicePrincipal",
"objectId": "aeb2d60b-0681-40f5-abe9-e0e66e793f3e",
"appDisplayName": "Windows Azure Active Directory",
"appId": "00000002-0000-0000-c000-000000000000",
}
//oAuth2PermissionGrants for user
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#oauth2PermissionGrants",
"value": [
{
"clientId": "2f9f4cf5-7576-42c9-8f9d-c1c3e6e63b4d",
"consentType": "Principal",
"expiryTime": "2018-03-30T21:31:15.7114922Z",
"id": "9UyfL3Z1yUKPncHD5uY7TQvWsq6BBvVAq-ng5m55Pz6rJZQ8BUBCT5nGOphIZSeR",
"principalId": "3c9425ab-4005-4f42-99c6-3a9848652791",
"resourceId": "aeb2d60b-0681-40f5-abe9-e0e66e793f3e",
"scope": "User.Read Directory.AccessAsUser.All",
"startTime": "0001-01-01T00:00:00Z"
},
{
"clientId": "2f9f4cf5-7576-42c9-8f9d-c1c3e6e63b4d",
"consentType": "Principal",
"expiryTime": "2018-03-30T21:31:15.7114922Z",
"id": "9UyfL3Z1yUKPncHD5uY7Tce3NkCwyX9EpdgYeU0NKiOrJZQ8BUBCT5nGOphIZSeR",
"principalId": "3c9425ab-4005-4f42-99c6-3a9848652791",
"resourceId": "4036b7c7-c9b0-447f-a5d8-18794d0d2a23",
"scope": "profile Files.ReadWrite.All Directory.ReadWrite.All Group.ReadWrite.All User.Read",
"startTime": "0001-01-01T00:00:00Z"
}
]
}
//Access tokens granted to user after sign-in
{
"aud": "https://graph.windows.net",
"scp": "Directory.AccessAsUser.All Directory.ReadWrite.All Files.ReadWrite.All Group.ReadWrite.All profile User.Read",
}
{
"aud": "https://graph.microsoft.com",
"scp": "Directory.AccessAsUser.All Directory.ReadWrite.All Files.ReadWrite.All Group.ReadWrite.All profile User.Read",
}
나는이 링크를 게시 할 수 없다는 이유로이 웹 사이트에서 삭제했습니다. 내가 얻은 액세스 토큰은 작동하지만 그 안에 포함 된 범위에 대해 혼란 스럽습니다. 범위 목록이 잘못되었습니다. 당신이 "요청"을 말할 때 당신이 의미하는 바를 모름 올바른 자원을 가진 요청을 통해 각각의 gotton에 대한 두 가지 다른 액세스 토큰이 있습니다. 하나는 MS Graph 용이고 다른 하나는 AAD 용입니다. JWT를 해독 할 때 각 토큰에 대한 aud가 올바른지 확인하지만 scp 소유권 주장에는 MS Graph와 AAD에 대한 클레임 목록이 포함되어 있습니다. –
'scope' 쿼리 매개 변수를 전달하면 사용자가 범위 집합에 대해 애플리케이션을 인증하도록 "요청"하고있는 것입니다. 이러한 범위는 처음에 사용자를 http : //login.microsoftonline.com /로 안내 할 때 전달됩니다. –
로그인에 대한 OWIN을 통해 요청되는 범위는 토큰과 같은 종류의 토큰처럼 보입니다. '... & scope = openid + 프로필 & ...'나는 액세스 토큰이 응용 프로그램의 servicePrincipal과 관련된 Oauth2PermissionGrants에서 해당 범위를 가져올 것으로 기대합니다. 따라서 사용자가 로그인하는 동안 모든 리소스의 모든 사용 권한에 동의하더라도 각 리소스에 대한 관련 범위가 각 액세스 토큰에 반환됩니다. 나는 그것을 보지 않고있다. –