Exemple #1
0
        public static bool TryParse(string tokenString, out SimpleWebToken token)
        {
            token = null;
            if (tokenString == String.Empty)
            {
                token = new SimpleWebToken();
                return(true);
            }

            if (tokenString == null)
            {
                return(false);
            }

            var claimPairs = tokenString.Split("&".ToArray());

            if (!claimPairs.All(x => x.Contains("=")))
            {
                return(false);
            }

            var claims = claimPairs
                         .Select(s => s.Split("=".ToArray()))
                         .Select(a => new Claim(a[0], a[1]));

            token = new SimpleWebToken(claims.ToArray());
            return(true);
        }
Exemple #2
0
        public string GetUserName(HttpRequestMessage request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.Headers.Authorization == null)
            {
                return(null);
            }
            if (request.Headers.Authorization.Scheme != "Bearer")
            {
                return(null);
            }

            SimpleWebToken swt;

            if (!SimpleWebToken.TryParse(request.Headers.Authorization.Parameter, out swt))
            {
                return(null);
            }

            return(swt
                   .Where(c => c.Type == "userName")
                   .Select(c => c.Value)
                   .SingleOrDefault());
        }
Exemple #3
0
        private string GetUserName()
        {
            SimpleWebToken swt;

            SimpleWebToken.TryParse(this.Request.Headers.Authorization.Parameter, out swt);
            var userName = swt.Single(c => c.Type == "userName").Value;

            return(userName);
        }