범위가 Azure AD의 Graph API가 아닌 경우 사용자 지정 클레임을 추가하고 access_token의 일부와 동일하게 검색하는 방법은 무엇입니까?

Aug 19 2020

Azure AD 웹 애플리케이션을 만들었습니다. 이제 다음 API를 사용하여 access_token을 얻고 있습니다.

우편 https://login.microsoftonline.com/{Directory (tenant) ID }/oauth2/v2.0/token

password:pass 
client_id:id
resource:https://graph.microsoft.com 
grant_type:password 
client_secret:secret 
sername:userName 
scope: https://rbsessence.onmicrosoft.com/0a7c94a0-0c4e-4f95-ba06-XXXX/.default

응답은 다음과 같습니다.

"token_type": "Bearer",
    "scope": "https://rbsessence.onmicrosoft.com/0a7c94a0-0c4e-4f95-ba06-XXXXX/myTestRole https://rbsessence.onmicrosoft.com/0a7c94a0-0c4e-4f95-ba06-XXXXXX/user_impersonation https://rbsessence.onmicrosoft.com/0a7c94a0-0c4e-4f95-ba06-XXXXX/.default",
    "expires_in": 3599,
    "ext_expires_in": 3599, "access_token": "acessToken"

이제 동일한 Azure AD 클라이언트로 구성된 타사 애플리케이션에 access_token을 전달하고 있습니다. 이제 제 3자가 "policy":"readwrite"access_token의 일부로 전달 될 이름으로 사용자 지정 클레임을 예상하고 있습니다. 어떻게 똑같이 할 수 있습니까?

답변

1 AllenWu Aug 20 2020 at 04:26

다음 단계를 참조하십시오 ( 시간을 절약하기 위해 Microsoft Graph Explorer 에서 Microsoft Graph 작업을 수행 할 수 있습니다 .) :

extensionProperty를 만듭니다 (여기에서 새로 만든 Azure AD 애플리케이션을 사용할 수 있음).

Post https://graph.microsoft.com/v1.0/applications/{object id of the Azure AD application}/extensionProperties

{"name":"policy","dataType":"string","targetObjects":["User"]}

라는 확장 속성이 생성됩니다 extension_{client id of the Azure AD application}_policy.

둘째, 계정의 확장 속성을 업데이트 할 수 있습니다.

Patch https://graph.microsoft.com/v1.0/me

{"extension_6d8190fbf1fe4bc38a5a145520221989_policy":"readwrite"}

그런 다음 claimMappingPolicy를 만듭니다 .

Post https://graph.microsoft.com/v1.0/policies/claimsMappingPolicies

{"definition":["{\"ClaimsMappingPolicy\":{\"Version\":1,\"IncludeBasicClaimSet\":\"true\", \"ClaimsSchema\": [{\"Source\":\"user\",\"ExtensionID\":\"extension_6d8190fbf1fe4bc38a5a145520221989_policy\",\"JwtClaimType\":\"policy\"}]}}"],"displayName":"ExtraClaimsAllen1Example","isOrganizationDefault":true}

servicePrincipal에 claimMappingPolicy 를 할당합니다 . 여기서 servicePrincipal은 타사 응용 프로그램을 나타내는 엔터프라이즈 응용 프로그램입니다. 귀하의 경우에는입니다 0a7c94a0-0c4e-4f95-ba06-XXXX.

Post https://graph.microsoft.com/v1.0/servicePrincipals/{obeject id of the servicePrincipal which represents your third party application}/claimsMappingPolicies/$ref

{"@odata.id":"https://graph.microsoft.com/v1.0/policies/claimsMappingPolicies/{policy id from the previous step}"}

Azure Portal- > Azure Active Directory- > 앱 등록 -> 타사 Azure AD 앱 찾기-> 개요 -> 연결된 서비스 주체의 이름을 클릭 하여 servicePrincipal을 찾을 수 있습니다 .

이제 타사 Azure AD 앱의 매니페스트 파일로 돌아갑니다. acceptMappedClaimstrue 및 accessTokenAcceptedVersion2로 설정하십시오 .

그런 다음 ROPC 권한 부여 흐름을 사용하여 타사 응용 프로그램에 대한 액세스 토큰을 요청하면 사용자 지정 클레임을 얻을 수 있습니다.