Identity Server not returning refresh token

前端 未结 2 634
故里飘歌
故里飘歌 2021-01-04 04:39

I\'m trying to set up Thinktecture\'s Identity Server 3, but I can\'t seem to get it to return a refresh token when exchanging an authorization code (or when using the Resou

相关标签:
2条回答
  • 2021-01-04 05:00

    You do have to explicitly ask for 'offline_access' in your request. Separate the other scopes you are requesting with a space. (In my examples below I am replacing 'Default' with 'MyApi' to be clear that we are talking about a scope defined by your app.)

    &scope=MyApi offline_access 
    

    However, you must also grant that client the right to get refresh tokens, it doesn't just happen based on the flow you pick:

    var client = new Client()
    {
        ... //All the stuff you were doing before
    
        ScopeRestrictions = new List<string>
        { 
            "MyApi",
            StandardScopes.OfflineAccess.Name, //"offline_access" -for refresh tokens
            //Other commonly requested scopes:
            //StandardScopes.OpenId.Name, //"openid"
            //StandardScopes.Email.Name,  //"email"
    
        },
    }
    

    You may need to add 'offline_access' to your scope store as well. The scope store is the list of scopes that Identity Server knows about. Your question doesn't mention how your scope store is set up in your project, so you may already have it. But if the above doesn't immediately work for you, you may want to look around for code like this in the example you're working from and add OfflineAccess.

    var scopeStore = new InMemoryScopeStore(new Scope[]{
        StandardScopes.OpenId,
        StandardScopes.Profile,
        StandardScopes.Email,
        StandardScopes.OfflineAccess,  //<--- ensure this is here to allow refresh tokens
        new Scope{
            Enabled = true,
            Name = "MyApi"
        },
    }
    
    0 讨论(0)
  • 2021-01-04 05:03

    Add offline_access value in scope while sending token request

    new Client
                {
                    ClientId = "ro.angular",
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
    
                    ClientSecrets =
                    {
                        new Secret("secret".Sha256())
                    },
                    AllowedScopes = {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        IdentityServerConstants.StandardScopes.Email,
                        IdentityServerConstants.StandardScopes.Address,
                        "api1",
                        IdentityServerConstants.StandardScopes.OfflineAccess
                    },
                    AllowOfflineAccess = true,
                    RefreshTokenUsage = TokenUsage.ReUse,
                    RefreshTokenExpiration = TokenExpiration.Sliding
    
                }
    

    0 讨论(0)
提交回复
热议问题