从 Identity Server4 刷新令牌和访问令牌

Refresh Token and Access Token from Identity Server4

我尝试使用以下方法获取访问令牌和刷新令牌,但它 returns invalid_scope 和错误请求。如果我删除范围的 offline_scope 值,它仅 returns 访问令牌。

 var tokenResponse = await protocolClient.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
                    {
                        Address = disco.TokenEndpoint,
                        ClientId = ServiceIdentity,
                        ClientSecret = ServiceKey,
                        Scope = "offline_access",
                        GrantType = "GrantTypes.ClientCredentials"
                    });
                    return tokenResponse.AccessToken;

这是设计使然。 GrantTypes.ClientCredentials 不支持刷新令牌。原因是您可以随时使用相同的客户端 ID 和密码获取新的访问令牌。