Exemple #1
0
        /// <summary>
        /// Login the current client with a JWT.
        /// </summary>
        /// <param name="jwt">The JWT to login with</param>
        /// <returns>A LoginResponse with all data</returns>
        public async Task <LoginResponse> LoginWithToken(string jwt)
        {
            var userInfo = getUserInfo(Context);

            if (userInfo.Value.JwtID != null)
            {
                return(new LoginResponse {
                    Success = false
                });
            }

            if (!_jwtFactory.Verify(jwt))
            {
                return(new LoginResponse {
                    Success = false
                });
            }

            var parsedToken = JWTFactory.Parse(jwt);

            if (_revokedTokenIds.Contains(parsedToken.JwtID))
            {
                return(new LoginResponse {
                    Success = false
                });
            }

            return(await connectUser(Context, parsedToken, jwt));
        }
Exemple #2
0
        public void T3_VerifyBadJWT()
        {
            byte[] key     = { 0xDE, 0xAD, 0xBE, 0xEF };
            var    payload = new JWTPayload {
                Subject = "24"
            };

            var jwtFactory = new JWTFactory(key);
            var jwt        = jwtFactory.Generate(payload);

            jwtFactory.Verify(jwt + "deadbeef").Should().BeFalse();
        }
Exemple #3
0
        public void T2_VerifyGoodJWT()
        {
            byte[] key     = { 0xDE, 0xAD, 0xBE, 0xEF };
            var    payload = new JWTPayload {
                Subject = "24"
            };

            var jwtFactory = new JWTFactory(key);
            var jwt        = jwtFactory.Generate(payload);

            jwtFactory.Verify(jwt).Should().BeTrue();
        }