Esempio n. 1
0
        /// <summary>
        /// 将整个token传入 返回 payload的 解码信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public string Decode(string token)
        {
            var payload = new JwtParts(token).Payload;
            var decoded = _urlEncoder.Decode(payload);

            return(GetString(decoded));
        }
Esempio n. 2
0
        /// <inheritdoc />
        /// <exception cref="ArgumentException" />
        /// <exception cref="InvalidTokenPartsException" />
        /// <exception cref="FormatException" />
        public string DecodeHeader(string token)
        {
            if (String.IsNullOrEmpty(token))
            {
                throw new ArgumentException(nameof(token));
            }

            var header  = new JwtParts(token).Header;
            var decoded = _urlEncoder.Decode(header);

            return(GetString(decoded));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public string Decode(string token, byte[] key, bool verify)
        {
            var parts = token.Split('.');

            if (parts.Length != 3)
            {
                throw new ArgumentException("Token must consist from 3 delimited by dot parts");
            }

            var payload     = parts[1];
            var payloadJson = Encoding.UTF8.GetString(_urlEncoder.Decode(payload));

            if (verify)
            {
                Validate(payload, payloadJson, parts, key);
            }

            return(payloadJson);
        }
Esempio n. 4
0
        /// <inheritdoc />
        /// <exception cref="ArgumentException" />
        /// <exception cref="ArgumentNullException" />
        /// <exception cref="ArgumentOutOfRangeException" />
        /// <exception cref="FormatException" />
        public string Decode(JwtParts jwt)
        {
            var decoded = _urlEncoder.Decode(jwt.Payload);

            return(GetString(decoded));
        }
Esempio n. 5
0
 /// <inheritdoc />
 public string Decode(string token) => Encoding.UTF8.GetString(_urlEncoder.Decode(new JwtParts(token).Payload));
Esempio n. 6
0
 /// <remarks>From JWT spec</remarks>
 public static byte[] Base64UrlDecode(string input)
 {
     return(_urlEncoder.Decode(input));
 }