代码之家  ›  专栏  ›  技术社区  ›  Hinrich

Azure AD:访问令牌中缺少角色声明

  •  8
  • Hinrich  · 技术社区  · 9 年前

    对于我的应用程序,我希望用户能够使用他们的Azure帐户登录(单点登录)。我还需要一个访问令牌来访问受保护的后端。 id_token 和 access_token ,并请求此url:

    https://login.microsoftonline.com/MY_TENANT_ID/oauth2/authorize?response_type=id_token+token&client_id=MY_CLIENT_ID&state=SOME_STATE&redirect_uri=MY_REDIRECT_URI&scope=openid profile&resource=MY_CLIENT_ID&nonce=SOME_NONCE
    

    这基本上是可行的,但我也希望在访问令牌(和id令牌)中具有角色,但是

    当我使用此Url仅获取 id\u令牌 , 包括角色声明 :

    https://login.microsoftonline.com/MY_TENANT_ID/oauth2/authorize?response_type=id_token&client_id=MY_CLIENT_ID&state=SOME_STATE&redirect_uri=MY_REDIRECT_URI&scope=openid profile&nonce=SOME_NONCE
    

    id\u令牌 token 我省略了 resource 参数

    id\u令牌 和 access\u令牌

    编辑:

    {
      "appId": "MY_CLIENT_ID",
      "appRoles": [
        {
          "allowedMemberTypes": [
            "User"
          ],
          "displayName": "Admin",
          "id": "c200e304-fff3-49f1-a4df-e406741ea690",
          "isEnabled": true,
          "description": "Bla bla",
          "value": "admin"
        },
        {
          "allowedMemberTypes": [
            "User"
          ],
          "displayName": "Reader",
          "id": "c534f351-b343-48d0-9dd7-ecb4c5cb402d",
          "isEnabled": true,
          "description": "Bla bla",
          "value": "reader"
        }
      ],
      "availableToOtherTenants": false,
      ...
    }
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   Fei Xue    9 年前

    作为这个问题的解决方法,我建议您在第一个请求中获取id\u令牌。然后,您可以使用adal库在iframe中获取访问令牌,而无需用户交互,因为用户已经登录。

    推荐文章