Beispiel #1
0
        public UserModule(IJwtKeyProvider keyProvider)
        {
            Post["/users/login", true] = async(x, ct) =>
            {
                Credentials creds = this.Bind <Credentials>(); // Model binding https://github.com/NancyFx/Nancy/wiki/Model-binding
                Console.WriteLine(creds);


                // Lookup user / pass from db

                if (creds.Username.Equals("admin") && creds.Password.Equals("admin"))
                {
                    var jwt = new JwtToken
                    {
                        Name       = creds.Username,
                        Expiration = DateTime.UtcNow.AddDays(2),
                        Roles      = new[] { "admin:false", "gender:man" },
                        Issuer     = keyProvider.Issuer,
                        Audience   = keyProvider.Audience
                    };

                    // Return Encrypted Token
                    return(Jose.JWT.Encode(jwt, keyProvider.Key, Jose.JwsAlgorithm.HS256));
                }

                await Task.Delay(100);

                return(HttpStatusCode.Unauthorized);
            };

            Get["/test/{id}"] = parameter => {
                return("OK");
            };
        }
Beispiel #2
0
 private static bool TheAudienceDoesNotMatch(IJwtKeyProvider provider, JwtToken jwt)
 {
     return(!provider.Audience.Equals(jwt.Audience));
 }
Beispiel #3
0
        //private bool TheUserIsNotValid(JwtToken jwt)

        //{

        //    return !_userMapper.IsUserValid(jwt.Name);

        //}



        private static bool TheIssuerDoesNotMatch(IJwtKeyProvider provider, JwtToken jwt)
        {
            return(!provider.Issuer.Equals(jwt.Issuer));
        }
Beispiel #4
0
 public StatelessAuthConfigurationFactory(IJwtKeyProvider keyProvider, IUserMapper userMapper)
 {
     _userMapper  = userMapper;
     _keyProvider = keyProvider;
 }
Beispiel #5
0
 public JwtGenerator(IJwtKeyProvider jwtKetProvider)
 {
     _jwtKetProvider = jwtKetProvider;
 }
 public StatelessAuthConfigurationFactory(IJwtKeyProvider keyProvider, IUserStore userStore)
 {
     this.keyProvider = keyProvider;
     this.userStore   = userStore;
 }