Ejemplo n.º 1
0
        public void ValidateSecurityTokenFacts(string tokenString, SecurityTokenStatus expectedStatus)
        {
            var ctx = new DefaultHttpContext();
            var req = ctx.Request;

            req.Headers.Add("Authorization", new StringValues(tokenString));

            var issuerToken = "bXlmdW5jdGlvbmF1dGh0ZXN0"; // base64 encoded for "myfunctionauthtest";
            Action <TokenValidationParameters> configureTokenValidationParameters = parameters =>
            {
                parameters.IssuerSigningKey         = new SymmetricSecurityKey(Convert.FromBase64String(issuerToken));
                parameters.RequireSignedTokens      = true;
                parameters.ValidateAudience         = false;
                parameters.ValidateIssuer           = false;
                parameters.ValidateIssuerSigningKey = true;
                parameters.ValidateLifetime         = true;
            };

            var securityTokenValidator = new DefaultSecurityTokenValidator(configureTokenValidationParameters);
            var securityTokenResult    = securityTokenValidator.ValidateToken(req);

            Assert.Equal(expectedStatus, securityTokenResult.Status);
        }
 private SecurityTokenResult(SecurityTokenStatus status, ClaimsPrincipal principal = null, Exception exception = null)
 {
     Status    = status;
     Principal = principal;
     Exception = exception;
 }