使用刷新令牌请求续订时,Azure AD returns 未签名的 ID 令牌

Azure AD returns Unsigned Id Token while requesting renewal using refresh token

我正在使用 Azure AD v1 终结点来授权我的 webapp。

在初始身份验证时,我没有让 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的客户端id/application 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