简体   繁体   English

如何为Azure AD创建和使用刷新令牌

[英]How to create and use a refresh token for Azure AD

I currently have an Azure website that is hooked up to an Azure Active Directory and users can currently sign in using this. 我目前有一个Azure网站连接到Azure Active Directory,用户当前可以使用此登录。

However, the access token that is created as part of the login process only enables users to remain logged in for one hour. 但是,作为登录过程的一部分创建的访问令牌仅允许用户保持登录一小时。 After some research I have found that this problem can be fixed with the introduction of a Refresh Token, which will enable the user to be logged in for longer. 经过一些研究后,我发现可以通过引入刷新令牌来解决这个问题,这将使用户能够登录更长时间。

The problem now is that i cannot find any code on how to actually create and use this refresh token in my project. 现在的问题是我找不到任何关于如何在我的项目中实际创建和使用此刷新令牌的代码。 Below is the library and code that I am using to communicate with Active Directory: 下面是我用来与Active Directory通信的库和代码:

using Microsoft.Owin.Security.ActiveDirectory;

    public class Startup {
        public void Configuration(IAppBuilder app) {
            var config = new HttpConfiguration();
            ConfigureAuth(app);
        }

        private void ConfigureAuth(IAppBuilder app) {
            app.UseWindowsAzureActiveDirectoryBearerAuthentication(
                new WindowsAzureActiveDirectoryBearerAuthenticationOptions {
                    TokenValidationParameters = new TokenValidationParameters {
                        ValidAudience = ConfigurationManager.AppSettings["ida:AudienceUri"]
                    },
                    Tenant = ConfigurationManager.AppSettings["AzureADTenant"]
                });
        }
    }

Look at active-directory-dotnet-webapp-webapi-oauth2-useridentity particularly how it utilizes the TokenDbCache in combination with ADAL to store refreshtokens. 查看active-directory-dotnet-webapp-webapi-oauth2-useridentity,特别是它如何将TokenDbCache与ADAL结合使用来存储refreshtokens。

When you configure ADAL AuthenticationContext with a TokenCache, ADAL will automatically try to retrieve a refresh token from the cache, if available and valid. 使用TokenCache配置ADAL AuthenticationContext时,ADAL将自动尝试从缓存中检索刷新令牌(如果可用且有效)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM