/// <summary>Initializes a new instance of the <see cref="MSALPerUserSqlTokenCacheProvider"/> class.</summary> /// <param name="tokenCacheDbContext">The token cache database context.</param> /// <param name="protectionProvider">The protection provider.</param> /// <param name="user">The current user .</param> /// <exception cref="ArgumentNullException">protectionProvider - The app token cache needs an {nameof(IDataProtectionProvider)}</exception> public MSALPerUserSqlTokenCacheProvider(ITokenCacheDbContext tokenCacheDbContext, IDataProtectionProvider protectionProvider, ClaimsPrincipal user) { if (protectionProvider == null) { throw new ArgumentNullException(nameof(protectionProvider), $"The app token cache needs an {nameof(IDataProtectionProvider)} to operate. Please use 'serviceCollection.AddDataProtection();' to add the data protection provider to the service collection"); } this.DataProtector = protectionProvider.CreateProtector("MSAL"); this.TokenCacheDb = tokenCacheDbContext; }
/// <summary>Initializes a new instance of the <see cref="EFMSALAppTokenCache"/> class.</summary> /// <param name="tokenCacheDbContext">The TokenCacheDbContext DbContext to read and write from Sql server.</param> /// <param name="azureAdOptionsAccessor"></param> /// <param name="protectionProvider">The data protection provider. Requires the caller to have used serviceCollection.AddDataProtection();</param> public MSALAppSqlTokenCacheProvider(ITokenCacheDbContext tokenCacheDbContext, IOptionsMonitor <AzureADOptions> azureAdOptionsAccessor, IDataProtectionProvider protectionProvider) { if (protectionProvider == null) { throw new ArgumentNullException(nameof(protectionProvider), $"The app token cache needs an {nameof(IDataProtectionProvider)} to operate. Please use 'serviceCollection.AddDataProtection();' to add the data protection provider to the service collection"); } if (azureAdOptionsAccessor.CurrentValue == null && string.IsNullOrWhiteSpace(azureAdOptionsAccessor.CurrentValue.ClientId)) { throw new ArgumentNullException(nameof(protectionProvider), $"The app token cache needs {nameof(AzureADOptions)}, populated with both Sql connection string and clientId to initialize."); } this.DataProtector = protectionProvider.CreateProtector("MSAL"); this.TokenCacheDb = tokenCacheDbContext; this.ActiveClientId = azureAdOptionsAccessor.CurrentValue.ClientId; }
/// <summary>Initializes a new instance of the <see cref="EFMSALPerUserTokenCache"/> class.</summary> /// <param name="protectionProvider">The data protection provider. Requires the caller to have used serviceCollection.AddDataProtection();</param> /// <param name="tokenCacheDbContext">The DbContext to the database where tokens will be cached.</param> /// <param name="httpContext">The current HttpContext that has a user signed-in</param> public MSALPerUserSqlTokenCacheProvider(ITokenCacheDbContext tokenCacheDbContext, IDataProtectionProvider protectionProvider, IHttpContextAccessor httpContext) : this(tokenCacheDbContext, protectionProvider, httpContext?.HttpContext?.User) { this.httpContextAccesssor = httpContext; }