Exemple #1
0
        /// <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(
            TokenCacheDbContext 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");
            }

            _dataProtector = protectionProvider.CreateProtector("MSAL");
            _tokenCacheDb  = tokenCacheDbContext;
            _signedInUser  = user;
        }
Exemple #2
0
        /// <summary>Initializes a new instance of the <see cref="MsalAppSqlTokenCacheProvider"/> 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(TokenCacheDbContext 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.");
            }

            _dataProtector  = protectionProvider.CreateProtector("MSAL");
            _tokenCacheDb   = tokenCacheDbContext;
            _activeClientId = azureAdOptionsAccessor.CurrentValue.ClientId;
        }
Exemple #3
0
 /// <summary>Initializes a new instance of the <see cref="MsalPerUserSqlTokenCacheProvider"/> 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>
 public MsalPerUserSqlTokenCacheProvider(
     TokenCacheDbContext tokenCacheDbContext,
     IDataProtectionProvider protectionProvider)
     : this(tokenCacheDbContext, protectionProvider, ClaimsPrincipal.Current)
 {
 }