Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfidentialClientApplicationBuilder with userTokenCache

Tags:

msal

I am unable to use ConfidentialClientApplicationBuilder with userTokenCache.

Code in samples look something like this but this code is obsolete now and I am supposed to use 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

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                       .Create(_azureAdOptions.ClientId)
                       .WithAuthority(authority)
                       .WithRedirectUri(currentUri)
                       .WithCertificate(clientCertificate)
                       .Build();
like image 670
user911 Avatar asked Nov 07 '22 09:11

user911


1 Answers

Its done a bit differently now.

You initialize the TokenCache implementation separately and attach it to the app object. see this line for reference.

Its highly recommended you study how the Token Cache is best implemented for MSAL. The TokenCacheProviders folder has the implementations.

like image 114
Kalyan Krishna Avatar answered Nov 17 '22 00:11

Kalyan Krishna