Exemple #1
0
        public static IServiceCollection AddTokens(this IServiceCollection services, Action <TokenGeneratorOptions> options)
        {
            var opt = new TokenGeneratorOptions();

            options(opt);

            return(services.AddSingleton(typeof(ITokenGenerator), new TokenGenerator(opt)));;
        }
Exemple #2
0
        public static void UseConfiguration(this TokenGeneratorOptions options, TokenConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            options.Audience          = (options.Audience == config.Audience) ? options.Audience : config.Audience;
            options.Issuer            = (options.Issuer == config.Issuer) ? options.Issuer : config.Issuer;
            options.Path              = (options.Path == config.AuthenticationPath) ? options.Path : config.AuthenticationPath; //Section already has a path property
            options.ExpirationMinutes = (options.ExpirationMinutes == config.ExpirationMinutes) ? options.ExpirationMinutes : config.ExpirationMinutes;
            //TODO: Add in new signing cred creation here for the token generator options
        }
Exemple #3
0
 public TokenGenerator(TokenGeneratorOptions opt) => this.opt = opt;
Exemple #4
0
 public TokenProviderMiddleware(RequestDelegate next, IOptions <TokenGeneratorOptions> options)
 {
     _next    = next;
     _options = options.Value;
     _fetcher = _options.PasswordValidator;
 }
Exemple #5
0
 public static IApplicationBuilder UseTokens(this IApplicationBuilder builder, TokenGeneratorOptions options)
 {
     return(builder.UseMiddleware <TokenProviderMiddleware>(Options.Create(
                                                                new TokenGeneratorOptions
     {
         PasswordValidator = (user, pass) => {
             //TODO: ***REMOVE THIS*** DEBUG ADMIN ACESS
             //TODO: Actually validate the username & password with the Identity classes
             if (user == "test" && pass == "test")
             {
                 Console.WriteLine($@"[Web.Jwt.TokenProviderMiddlewareExtensions.PasswordValidator({user}, {pass})] **DEBUG** USING U:test P:test == true - creating new GenericIdentity({user}, {JwtDefaults.TokenProviderUserClaimsBase}");
                 return new GenericIdentity(user, JwtDefaults.TokenProviderUserClaimsBase);
             }
             return null;
         }
     }
                                                                )));
 }