protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            string authHeader = request.Headers.GetValues("Authorization").First();

            string header = "OAuth ";
            string token = string.Empty;

            if (string.CompareOrdinal(authHeader, 0, header, 0, header.Length) == 0)
            {
                token = authHeader.Remove(0, header.Length);
            }
            else
            {
                throw new HttpException((int)System.Net.HttpStatusCode.Unauthorized, "The authorization header was invalid");
            }

            var validator = new SimpleWebTokenValidator
            {
                SharedKeyBase64 = "yourtokensigningkey"
            };

            var swt = validator.ValidateToken(token);

            return base.SendAsync(request, cancellationToken);
        }
예제 #2
0
        private static void TestValidToken(string token)
        {
            var validator = new SimpleWebTokenValidator();
            validator.SharedKeyBase64 = SharedKeyBase64;

            SimpleWebToken swt = null;
            try
            {
                swt = validator.ValidateToken(token);
                Console.WriteLine("Valid token");
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.ToString());
            }

            if (swt != null)
            {
                foreach (var claim in swt.Claims)
                {
                    Console.WriteLine(claim.Key + ":" + claim.Value);
                }
            }
        }