示例#1
0
 public TokenProviderMiddleware(
     RequestDelegate next,
     IOptions <TokenProviderOptions> options)
 {
     _next    = next;
     _options = options.Value;
 }
示例#2
0
 public TokenProviderMiddleware(
     RequestDelegate next,
     IOptions <TokenProviderOptions> options,
     SignInManager <ApplicationUser> signInManager)
 {
     _signInManager = signInManager;
     _next          = next;
     _options       = options.Value;
 }
 public TokenProviderMiddleware(
     RequestDelegate next,
     IOptions <TokenProviderOptions> options,
     EscolaDeVoce.Services.Interfaces.IUserService userService)
 {
     _next        = next;
     _options     = options.Value;
     _userService = userService;
 }
示例#4
0
        public TokenProviderMiddleware(
            RequestDelegate next,
            IOptions <TokenProviderOptions> options,
            ILoggerFactory loggerFactory)
        {
            _next   = next;
            _logger = loggerFactory.CreateLogger <TokenProviderMiddleware>();

            _options = options.Value;
            ThrowIfInvalidOptions(_options);

            _serializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
        }
示例#5
0
        private static void ThrowIfInvalidOptions(TokenProviderOptions options)
        {
            if (string.IsNullOrEmpty(options.Path))
            {
                throw new ArgumentNullException(nameof(TokenProviderOptions.Path));
            }

            if (string.IsNullOrEmpty(options.Issuer))
            {
                throw new ArgumentNullException(nameof(TokenProviderOptions.Issuer));
            }

            if (string.IsNullOrEmpty(options.Audience))
            {
                throw new ArgumentNullException(nameof(TokenProviderOptions.Audience));
            }

            if (options.ExpirationAccessToken == TimeSpan.Zero)
            {
                throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(TokenProviderOptions.ExpirationAccessToken));
            }

            if (options.ExpirationRefreshToken == TimeSpan.Zero)
            {
                throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(TokenProviderOptions.ExpirationRefreshToken));
            }

            if (options.IdentityResolver == null)
            {
                throw new ArgumentNullException(nameof(TokenProviderOptions.IdentityResolver));
            }

            if (options.SigningCredentials == null)
            {
                throw new ArgumentNullException(nameof(TokenProviderOptions.SigningCredentials));
            }

            if (options.SigningRTokenCredentials == null)
            {
                throw new ArgumentNullException(nameof(TokenProviderOptions.SigningRTokenCredentials));
            }

            if (options.NonceGenerator == null)
            {
                throw new ArgumentNullException(nameof(TokenProviderOptions.NonceGenerator));
            }
        }
        /// <summary>
        /// Adds the <see cref="TokenProviderMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables token generation capabilities.
        /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
        /// <param name="options">A  <see cref="TokenProviderOptions"/> that specifies options for the middleware.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IApplicationBuilder UseSimpleTokenProvider(this IApplicationBuilder app, TokenProviderOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(app.UseMiddleware <TokenProviderMiddleware>(Options.Create(options)));
        }