예제 #1
0
        public void DecodedAccessTokenShouldBeValid(
            string publicKey,
            string issuer,
            string audience,
            string accessToken,
            string expectedUserId,
            string expectedGivenName,
            string expectedFamilyName)
        {
            var accessTokenSettings = new AccessTokenSettings
            {
                PublicKey = publicKey,
                Issuer    = issuer,
                Audience  = audience
            };

            var AccessTokenProvider = new AccessTokenProvider(accessTokenSettings);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = $"Bearer {accessToken}";

            var accessTokenResult = AccessTokenProvider.ValidateToken(httpContext.Request);

            Assert.Equal(AccessTokenStatus.Valid, accessTokenResult.Status);
            Assert.Equal(expectedUserId, accessTokenResult.Principal.GetUserId());
            Assert.Equal(expectedGivenName, accessTokenResult.Principal.GetGivenName());
            Assert.Equal(expectedFamilyName, accessTokenResult.Principal.GetFamilyName());
        }
        public AccessTokenResult ValidateToken(string accessToken)
        {
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = $"Bearer {accessToken}"; //Set header

            return(AccessTokenProvider.ValidateToken(httpContext.Request));
        }