简体   繁体   English

带有 userTokenCache 的 ConfidentialClientApplicationBuilder

[英]ConfidentialClientApplicationBuilder with userTokenCache

I am unable to use ConfidentialClientApplicationBuilder with userTokenCache.我无法将 ConfidentialClientApplicationBuilder 与 userTokenCache 一起使用。

Code in samples look something like this but this code is obsolete now and I am supposed to use ConfidentialClientApplicationBuilder.示例中的代码看起来像这样,但此代码现在已过时,我应该使用 ConfidentialClientApplicationBuilder。

ConfidentialClientApplication app;
            var request = httpContext.Request;
            var currentUri = UriHelper.BuildAbsolute(request.Scheme, request.Host, request.PathBase, _azureAdOptions.CallbackPath ?? string.Empty);
            var credential = new ClientCredential(_azureAdOptions.ClientSecret);
            TokenCache userTokenCache = _tokenCacheProvider.GetCache(httpContext, claimsPrincipal, authenticationProperties, signInScheme);
            string authority = $"{_azureAdOptions.Instance}{_azureAdOptions.TenantId}/";
            app = new ConfidentialClientApplication(_azureAdOptions.ClientId, authority, currentUri, credential, userTokenCache, null);
            return app;

ConfidentialClientApplicationBuilder Code ConfidentialClientApplicationBuilder 代码

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                       .Create(_azureAdOptions.ClientId)
                       .WithAuthority(authority)
                       .WithRedirectUri(currentUri)
                       .WithCertificate(clientCertificate)
                       .Build();

Its done a bit differently now.现在它的做法有点不同。

You initialize the TokenCache implementation separately and attach it to the app object.您单独初始化 TokenCache 实现并将其附加到应用程序对象。 see this line for reference.请参阅此行以供参考。

Its highly recommended you study how the Token Cache is best implemented for MSAL.强烈建议您研究如何最好地为 MSAL 实现令牌缓存。 The TokenCacheProviders folder has the implementations. TokenCacheProviders文件夹具有实现。

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

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