【问题标题】:Azure AD returns Unsigned Id Token while requesting renewal using refresh tokenAzure AD 在使用刷新令牌请求续订时返回 Unsigned Id 令牌
【发布时间】:2018-11-18 11:50:36
【问题描述】:

我正在使用 Azure AD v1 端点来授权我的 web 应用程序。

在初始身份验证时,我没有让 access_token 成为有效的 jwt 令牌。但是我让 id_token 成为有效的 jwt,而 acces_token 成为 refresh_token 的值,这看起来很奇怪。

我可以使用 id_token 作为不记名令牌来调用我的 Web API。都很好。

现在当 id_token 过期时,我正在使用我的 refresh_token 发送以下刷新令牌请求。我收到未签名的 id_token 作为响应。由于新的 id_token 未签名,因此使用此 id_token 我无法访问 Web API。 我错过了什么吗?

POST /token HTTP/1.1
Host: {authority}
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&
client_id=mvc&
client_secret=secret&
refresh_token=AQABAAAAAADX8GCi6J
&scope=openid%20profile%20offline_access

我正在使用以下启动配置来设置身份验证

services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddCookie(options =>
            {
                options.ExpireTimeSpan = TimeSpan.FromSeconds(1000);
                options.Cookie.Name = "mvcapplication";
            })
            .AddOpenIdConnect(option=>{
        options.Authority = "{aad v1 endpoint}";
                options.ClientId = "mvc";
                options.ClientSecret = "secret";
                options.ResponseType = "code id_token";
                options.ResponseMode = "form_post";
                options.SignInScheme = "Cookies";
                options.CallbackPath = "/Home/Index/";
                options.RequireHttpsMetadata = false;
                options.SaveTokens = true;
                options.GetClaimsFromUserInfoEndpoint = true;

                //Default Scopes
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.Scope.Add("offline_access");
         });

【问题讨论】:

  • 嗯,你应该使用访问令牌来调用 API :)
  • @juunas 在评论 GetClaimsFromUserInfoEndpoint 属性时获得有效的 access_token
  • 你刚刚回答了你自己的问题 :) JWT Bearer options Audience 应该是 API 的客户端 ID。如果您将其设置为 Web App 的客户端 id,它将只接受给 Web App 的 id 令牌,并且您本质上共享应用程序身份。
  • 当您在 API 的 JWT 选项中配置 Audience/ValidAudience/ValidAudiences 时,会配置验证以检查令牌中的 aud 声明是否与配置的内容匹配。如果没有,你会得到一个 401。
  • @juunas 完美……我现在明白我的错误了……非常感谢!!

标签: azure-active-directory openid-connect refresh-token azure-ad-b2b


【解决方案1】:

总结一下cmets中的讨论:

  • 获取访问令牌时,使用 API 的客户端 ID/应用 ID 或应用 ID URI 作为resource
  • 将 API 配置为接受上述一项或两项作为有效受众
  • 删除 GetClaimsFromUserInfoEndpoint 提供了有效的访问令牌

您可以在此处查看有关在 ASP.NET Core MVC (2.0) 应用中设置 Azure AD 身份验证的更多信息:https://joonasw.net/view/aspnet-core-2-azure-ad-authentication

您还可以在此处找到示例应用程序:https://github.com/juunas11/aspnetcore2aadauth

【讨论】:

    猜你喜欢
    • 2016-01-05
    • 2018-01-21
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2020-07-05
    • 1970-01-01
    相关资源
    最近更新 更多