スコープがAzureADのGraphAPIでない場合に、カスタムクレームを追加し、access_tokenの一部として同じものを取得するにはどうすればよいですか?
Azure ADWebアプリケーションを作成しました。現在、次の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"
ここで、同じAzureADクライアントで構成されているサードパーティアプリケーションにaccess_tokenを渡します。これで、サードパーティは"policy":"readwrite"
、access_tokenの一部として渡される名前によるカスタムクレームを期待しています。どうすれば同じことを達成できますか?
回答
次の手順を参照してください(時間を節約するために、Microsoft GraphExplorerでMicrosoftGraph操作を実行できます)。
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"}
次に、claimsMappingPolicyを作成します。
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}
claimsMappingPolicyをservicePrincipalに割り当てます。ここでの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}"}
servicePrincipalは、Azure Portal- > Azure ActiveDirectory- >アプリの登録->サードパーティのAzureADアプリの検索->概要->関連するサービスプリンシパルの名前をクリックして見つけることができます。


次に、サードパーティのAzureADアプリのマニフェストファイルに戻ります。acceptMappedClaims
trueおよびaccessTokenAcceptedVersion
2に設定します。

次に、ROPCグラントフローを使用してサードパーティアプリケーションのアクセストークンをリクエストすると、カスタムクレームを取得できます。
