Azure AD OAuth流向我返回“ id令牌”。我需要“访问令牌”才能获得组列表

时间:2018-11-14 21:42:59

标签: azure-active-directory

在我的Azure AD应用程序清单中,我有"groupMembershipClaims": "SecurityGroup" 但是,我通过Azure AD OAuth2身份验证获得的JWT令牌不包含“组”或“ hasGroups”字段。

经过研究,我发现了这个非常简短的答案: Azure ad group membership claims

似乎在进行OAuth2身份验证之后,我得到了id token,我需要找出一种获得access token的方法

我如何通过Azure AD OAuth2身份验证向我发送“访问令牌”?

更新

谢谢@Philippe Signoret看看这个。

通过以下步骤创建AAD应用程序:

https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-protect-backend-with-aad

可以使用以下隐式流URL来解决该问题:

https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?client_id={app id}&response_type=token&redirect_uri=http%3A%2F%2Flocalhost%2f&scope=openid&state=12345&nonce=678910

这是设置groupMembershipClaims的方式:

enter image description here

缺少分组的JWT看起来像这样:

{
    "aud": "00000003-0000-0000-c000-000000000000",
    "iss": "https://sts.windows.net/XXXXXXXXXX--XXXXXXXXXX/",
    "iat": XXXXXXXXXX,
    "nbf": XXXXXXXXXX,
    "exp": XXXXXXXXXX,
    "acct": 1,
    "acr": "1",
    "aio": "XXXXXXXXXX",
    "altsecid": "5::XXXXXXXXXX",
    "amr": [
        "pwd"
    ],
    "app_displayname": "XXXXXXXXXX",
    "appid": "XXXXXXXXXX",
    "appidacr": "0",
    "email": "XXXXXXXXXX",
    "idp": "https://sts.windows.net/XXXXXXXXXX/",
    "ipaddr": "XXXXXXXXXX",
    "name": "XXXXXXXXXX",
    "oid": "XXXXXXXXXX",
    "platf": "3",
    "puid": "XXXXXXXXXX",
    "scp": "Directory.Read.All User.Read profile openid email",
    "signin_state": [
        "kmsi"
    ],
    "sub": "XXXXXXXXXX",
    "tid": "XXXXXXXXXX",
    "unique_name": "XXXXXXXXXX",
    "uti": "XXXXXXXXXX",
    "ver": "1.0",
    "xms_st": {
        "sub": "XXXXXXXXXX"
    },
    "xms_tcdt": XXXXXXXXXX
}

1 个答案:

答案 0 :(得分:0)

对于大多数身份提供者,将response_type参数作为id_token token而不是token发送,同时从令牌端点返回访问令牌和id令牌。我建议您也在Azure中尝试相同的方法。