asp.net - 如何使用 Identityserver4 请求刷新 token

标签 asp.net asp.net-identity identityserver4

我有 IdentityServer 和一个使用资源所有者流程的单独的 WebApi 项目。

当我请求如下 token 时, token 将被颁发并可用于访问 WebApi。所以我假设 IdentityServer 已正确设置,并且 WebApi 项目也已正确设置。

username=user1
password=user1password
grant_type=password
client_id=myClientId
client_secret=myClientSecret
scope=api1

现在,当我将授予类型更改为刷新并将范围更改为离线访问时,我会获得刷新 token 。然后,我使用刷新 token 来获取访问 token ,但是当我使用访问 token 请求 WebApi 时,它被拒绝。

有错误

the audience is invalid

我怀疑这是因为我要求offline_access范围而不是WebApi项目期望的api1范围。如何获取可与范围 api1 一起使用的刷新 token ?

最佳答案

 var model =       {
                    client_id: "myClientId",
                    client_secret: "myClientSecret",
                    scope: "api1 offline_access",
                    token_type: "Bearer", //Optional
                    grant_type: "refresh_token",
                    refresh_token: "your refresh token"
                };


//this is most important step when to use refresh token 

 var base64 = btoa(model.client_id + ":" + model.client_secret); 

//and your request here

this.$http({
                method: "POST",
                url: "/connect/token",
                headers: {
                    'content-type': "application/x-www-form-urlencoded",
                    'Authorization': "Basic " + base64
                },
                data: jQuery.param(model)
            })
                .then(
                response => {


                  //success


                },
                response => {

                    //logout
                });

关于asp.net - 如何使用 Identityserver4 请求刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45316535/

相关文章:

c# - 强制转换以从所选中获取 ID 不起作用

c# - 在 ASP.NET Core Identity 中检查具有 Authorize 属性的多个策略之一

asp.net - 如何定义多个部分 Owin Startup 类并让它们全部运行其代码

c# - IOptions 不适用于 TinyIOC/NancyFX

asp.net - Ajax 控制工具包 ModalPopupExtender 在 Visual Studio 2012 中不起作用

asp.net - Blazor ASP.Net Core 3.1 Web API 发布时返回 404 错误

AngularJS - IdentityServer4.Quickstart.UI - 'AuthenticationProperties' 是一个模棱两可的引用

c# - 如何将 IsActiveAsync 失败信息传递给用户和客户端?

asp.net-core - IdentityServer 4 多个外部 Active Directory 提供商

c# - 如何在IdentityServer4/Identity中配置角色声明名称