public BearerSignInManager(IOptions <BearerSignInManagerOptions> options,
                            UserManager <UserType> userManager, IOptions <IdentityOptions> identityOptions,
                            IBearerTokenStore <BearerTokenType> bearerTokenStore, ILogger <BearerSignInManager <UserType, BearerTokenType> >?logger = null)
 {
     errorDetailsProvider  = new ErrorDetailsProvider(() => options.Value.IncludeErrorDetails, logger);
     signInManagerOptions  = options.Value;
     this.userManager      = userManager;
     this.identityOptions  = identityOptions;
     this.bearerTokenStore = bearerTokenStore;
     this.logger           = logger;
 }
コード例 #2
0
        public AccountsService(HttpClient httpClient, IConfiguration configuration, IBearerTokenStore bearerTokenStore)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }
            _http = httpClient;

            // if configuration is not provided, read from environment variables
            _config = configuration ?? new ConfigurationBuilder()
                      .AddEnvironmentVariables()
                      .Build();
            ValidateConfig();

            _bearerTokenStore = bearerTokenStore ?? new MemoryBearerTokenStore();
        }
コード例 #3
0
        public UserAccountsService(
            HttpClient httpClient,
            IConfiguration configuration,
            IRefreshTokenProvider refreshTokenProvider,
            IBearerTokenStore bearerTokenStore
            ) : base(httpClient, configuration, bearerTokenStore)
        {
            //TODO: when does this get called?
            ValidateConfig();

            if (refreshTokenProvider == null)
            {
                throw new ArgumentNullException("userTokenStore");
            }
            _refreshTokenProvider = refreshTokenProvider;
        }
コード例 #4
0
        /// <summary>
        /// It tries to resolve refresh token id from claim <see cref="BearerSignInManagerDefaults.SignInServiceRefreshTokenIdClaimType"/>
        /// and then look in the database. If a refresh token has been found, it will be returned.
        /// </summary>
        public static async Task <ServiceResult <BearerTokenType> > FindRefreshTokenAsync <BearerTokenType>(IBearerTokenStore <BearerTokenType> refreshTokenStore, ClaimsPrincipal principal, ILogger?logger = null)
            where BearerTokenType : class, IBearerTokenEntity
        {
            principal = principal ?? throw BearerSignInManagerThrowHelper.GetPrincipalNullException(nameof(principal));
            var refreshTokenIdResult = FindRefreshTokenId(principal);

            if (!refreshTokenIdResult.Succeeded)
            {
                return(ServiceResult <BearerTokenType> .Failure(refreshTokenIdResult));
            }

            try {
                // Then we need the entity that belongs to refresh token id.
                var refreshTokenEntity = await refreshTokenStore.FindAsync(refreshTokenIdResult.Content);

                return(ReferenceEquals(refreshTokenEntity, null) ?
                       ServiceResult <BearerTokenType>
                       .Failure("The refresh token has been redeemed.")
                       .WithHttpStatusCode(HttpStatusCode.BadRequest) :
                       ServiceResult <BearerTokenType>
                       .Success(refreshTokenEntity)
                       .WithHttpStatusCode(HttpStatusCode.OK));
            } catch (Exception error) {
                const string errorMessage = "Search for refresh token failed.";
                logger?.LogError(error, errorMessage);

                return(errorMessage.ToJsonError()
                       .ToServiceResult <BearerTokenType>()
                       .WithHttpStatusCode(HttpStatusCode.InternalServerError));
            }
        }
コード例 #5
0
 public BearerSignInManager(IOptions <BearerSignInManagerOptions> options, UserManager <UserEntity> userManager,
                            IOptions <IdentityOptions> identityOptions, IBearerTokenStore bearerTokenStore,
                            ILogger <BearerSignInManager>?logger = null)
     : base(options, userManager, identityOptions, bearerTokenStore, logger)
 {
 }