C# .net core 3.1:如果访问令牌过期,如何使用AcquireTokenAsync方法获取新令牌?

C# .net core 3.1:如果访问令牌过期,如何使用AcquireTokenAsync方法获取新令牌?,c#,.net,.net-core,oauth-2.0,openid,C#,.net,.net Core,Oauth 2.0,Openid,我的客户端应用程序,即webchat使用openid身份验证和生成的访问令牌,也会在调用graph API时传递给bot使用 启动代码: services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme

我的客户端应用程序,即webchat使用openid身份验证和生成的访问令牌,也会在调用graph API时传递给bot使用

启动代码:

 services.AddAuthentication(options =>
        {
            options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        })
        //.AddAzureAd(options => this.Configuration.Bind("Authentication:AzureAd", options))
        .AddCookie()
        .AddOpenIdConnect(options =>
        {
            options.ClientId = "cid";
            options.ClientSecret = "csercet";
            options.Authority = string.Format(azureAdConfig.Instance, azureAdConfig.TenantId);
            options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
            options.Resource = "https://graph.microsoft.com/";
            options.Events = new AuthEvents(azureAdConfig);
        });
在authevents中接收到授权代码后,将生成访问令牌:

    public override async Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context)
    {
        var principal = context.Principal;
        var request = context.HttpContext.Request;
        var currentUri = UriHelper.BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path);

        var tokenService = (ITokenService)context.HttpContext.RequestServices.GetService(typeof(ITokenService));
        try
        {
            var x = await tokenService.RequestTokenAsync(principal, context.ProtocolMessage.Code, currentUri, "https://graph.microsoft.com/")
                 .ConfigureAwait(false);
            context.HandleCodeRedemption(x.AccessToken, x.IdToken);
        }
        catch (System.Exception ex)
        {               
            throw;
        }
    }

如何在.net core 3.1中访问令牌到期时获取新令牌?

若我尝试使用AcquiretokenAsync方法,那个么它需要PlatformParameters作为参数,以实现接口ICustomWebUi

我看不到它的实现有任何用处,所以我传递了null,但作为customWebUi获取错误不能作为null传递
代码: 参数类别:

    #region Assembly Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// C:\Users\v-sagkul\.nuget\packages\microsoft.identitymodel.clients.activedirectory\5.2.8\lib\netstandard1.3\Microsoft.IdentityModel.Clients.ActiveDirectory.dll
#endregion

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.IdentityModel.Clients.ActiveDirectory.Extensibility;

namespace Microsoft.IdentityModel.Clients.ActiveDirectory
{
    //
    // Summary:
    //     Additional parameters used in acquiring user's authorization.
    public class PlatformParameters : IPlatformParameters
    {
        //
        // Summary:
        //     Constructor that allows extends to configure their own web ui. Not implemented
        //     on Android, iOS and UWP.
        //
        // Parameters:
        //   promptBehavior:
        //     Controls the prompt that is displayed on web ui. Default is Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.SelectAccount.
        //
        //   customWebUi:
        //     Custom implementation of the web ui
        //
        // Remarks:
        //     This object is platform specific and should not be constructed from NetStandard
        //     (shared) assemblies.
        public PlatformParameters(PromptBehavior promptBehavior, ICustomWebUi customWebUi);

        //
        // Summary:
        //     Gets the configured prompt behavior
        public PromptBehavior PromptBehavior { get; }
        //
        // Summary:
        //     Extension method enabling ADAK.NET extenders for public client applications to
        //     set a custom web ui that will let the user sign-in with Azure AD, present consent
        //     if needed, and get back the authorization code.
        public ICustomWebUi CustomWebUi { get; }
    }
}

你找到解决这个问题的办法了吗?您实现了CustomWebUI吗?
    #region Assembly Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// C:\Users\v-sagkul\.nuget\packages\microsoft.identitymodel.clients.activedirectory\5.2.8\lib\netstandard1.3\Microsoft.IdentityModel.Clients.ActiveDirectory.dll
#endregion

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.IdentityModel.Clients.ActiveDirectory.Extensibility;

namespace Microsoft.IdentityModel.Clients.ActiveDirectory
{
    //
    // Summary:
    //     Additional parameters used in acquiring user's authorization.
    public class PlatformParameters : IPlatformParameters
    {
        //
        // Summary:
        //     Constructor that allows extends to configure their own web ui. Not implemented
        //     on Android, iOS and UWP.
        //
        // Parameters:
        //   promptBehavior:
        //     Controls the prompt that is displayed on web ui. Default is Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.SelectAccount.
        //
        //   customWebUi:
        //     Custom implementation of the web ui
        //
        // Remarks:
        //     This object is platform specific and should not be constructed from NetStandard
        //     (shared) assemblies.
        public PlatformParameters(PromptBehavior promptBehavior, ICustomWebUi customWebUi);

        //
        // Summary:
        //     Gets the configured prompt behavior
        public PromptBehavior PromptBehavior { get; }
        //
        // Summary:
        //     Extension method enabling ADAK.NET extenders for public client applications to
        //     set a custom web ui that will let the user sign-in with Azure AD, present consent
        //     if needed, and get back the authorization code.
        public ICustomWebUi CustomWebUi { get; }
    }
}