コード例 #1
0
        //  private AuthenticationContext authContext;
        //  private Task<ClientCredential> credential;

        public AzureB2CUserService(
            IOptions <AzureB2CUserServiceConfiguration> options,
            IHttpClientFactory httpClientFactory,
            IAzureB2CUserServiceAutenticationService azureB2CUserServiceAutenticationService,
            ILogger <AzureB2CUserService> logger,
            IHostingEnvironment hostingEnvironment)
        {
            _configuration     = options.Value ?? throw new ArgumentNullException(nameof(options));
            _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
            _azureB2CUserServiceAutenticationService = azureB2CUserServiceAutenticationService ?? throw new ArgumentNullException(nameof(azureB2CUserServiceAutenticationService));
            _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
            _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
        }
コード例 #2
0
        public AzureB2CUserServiceAutenticationService(IOptions <AzureB2CUserServiceConfiguration> options)
        {
            _configuration = options.Value ?? throw new ArgumentNullException(nameof(options));

            _authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/" + _configuration.TenantId);

            _token = new AsyncExpiringLazy <string>(async(old) =>
            {
                AuthenticationResult result = await _authenticationContext.AcquireTokenAsync(aadGraphResourceId, new ClientCredential(_configuration.ApplicationId, _configuration.ClientSecret));

                return(new ExpirationMetadata <string> {
                    ValidUntil = result.ExpiresOn.AddMinutes(5), Result = result.AccessToken
                });
            });
        }