簡體   English   中英

訪問令牌過期時如何使Owin自動使用刷新令牌

[英]How to make Owin automatically use refresh token when access token expires

我有一個連接到 IdentityServer 4 的 Owin 客戶端,我想知道如何讓 owin 使用刷新令牌請求新的 access_token。 我可以成功地使用以下配置交換為 access_token、id_token 和 refresh_token 提供的代碼:

public void Configuration(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookie"
            });
            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority = "http://localhost:5000",
                ClientId = "mywebsite",
                ClientSecret = "secret",
                RedirectUri = "https://localhost:5001/",
                ResponseType = "code",
                RequireHttpsMetadata = false,
                SaveTokens = true,
                UseTokenLifetime = true,
                SignInAsAuthenticationType = "Cookie",
                Scope = "openid profile email offline_access",
                RedeemCode = true,
                
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = n =>
                    {
                        Console.WriteLine(n);
                        return System.Threading.Tasks.Task.FromResult(0);
                    },
                    TokenResponseReceived = n =>
                    {
                        Console.WriteLine(n);
                        return System.Threading.Tasks.Task.FromResult(0);
                    }
                },
                
            });
        }

首先,我將這些令牌保存到哪里? 我可以訪問他們所有的 SecurityTokenValidated 回調 - 他們應該 go 進入索賠? 數據庫? Memory?

其次,我在我的 IdentityServer 客戶端配置中將 access_token 壽命設置為 60s,identity_token 設置為 3600s,並刷新為 30 天(請注意 access_token 僅用於測試目的)。 那么如何配置 Owin 以識別 access_token 已過期,並且它需要使用 refresh_token 將 go 返回到 identityserver 並獲取新的。 帶有示例代碼片段的答案將不勝感激,因為我對這一切的了解非常少。

相關信息:IS4 v3.Net Framework v4.6 客戶端在 IS 中設置為允許離線訪問

看看這篇文章:

除此之外,AddOpenIdConnect(..) 處理程序中沒有任何邏輯來處理刷新令牌的更新。 我認為這取決於您的應用程序來刷新它們。 如果您已將刷新令牌保存在安全的地方,那么在代碼中刷新它們並不難。

看到這個問題How to use 'refresh_token' in IdentityServer 4?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM