コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JwtSecurityToken"/> class where the <see cref="JwtHeader"/> contains the crypto algorithms applied to the encoded <see cref="JwtHeader"/> and <see cref="JwtPayload"/>. The jwtEncodedString is the result of those operations.
        /// </summary>
        /// <param name="header">Contains JSON objects representing the cryptographic operations applied to the JWT and optionally any additional properties of the JWT</param>
        /// <param name="payload">Contains JSON objects representing the claims contained in the JWT. Each claim is a JSON object of the form { Name, Value }</param>
        /// <exception cref="ArgumentNullException">'header' is null.</exception>
        /// <exception cref="ArgumentNullException">'payload' is null.</exception>
        public JwtSecurityToken(JwtHeader header, JwtPayload payload)
        {
            if (header == null)
            {
                throw LogHelper.LogArgumentNullException("header");
            }

            if (payload == null)
            {
                throw LogHelper.LogArgumentNullException("payload");
            }

            Header       = header;
            Payload      = payload;
            RawSignature = string.Empty;
        }
コード例 #2
0
        /// <summary>
        /// Initializes an instance of <see cref="JwtSecurityToken"/> where the <see cref="JwtHeader"/> contains the crypto algorithms applied to the innerToken <see cref="JwtSecurityToken"/>.
        /// </summary>
        /// <param name="header">Defines cryptographic operations applied to the 'innerToken'.</param>
        /// <param name="innerToken"></param>
        /// <param name="rawEncryptedKey">base64urlencoded key</param>
        /// <param name="rawHeader">base64urlencoded JwtHeader</param>
        /// <param name="rawInitializationVector">base64urlencoded initialization vector.</param>
        /// <param name="rawCiphertext">base64urlencoded encrypted innerToken</param>
        /// <param name="rawAuthenticationTag">base64urlencoded authentication tag.</param>
        /// <exception cref="ArgumentNullException">'header' is null.</exception>
        /// <exception cref="ArgumentNullException">'innerToken' is null.</exception>
        /// <exception cref="ArgumentNullException">'rawHeader' is null.</exception>
        /// <exception cref="ArgumentNullException">'rawEncryptedKey' is null.</exception>
        /// <exception cref="ArgumentNullException">'rawInitialVector' is null or whitespace.</exception>
        /// <exception cref="ArgumentNullException">'rawCiphertext' is null or whitespace.</exception>
        /// <exception cref="ArgumentNullException">'rawAuthenticationTag' is null or whitespace.</exception>
        public JwtSecurityToken(JwtHeader header,
                                JwtSecurityToken innerToken,
                                string rawHeader,
                                string rawEncryptedKey,
                                string rawInitializationVector,
                                string rawCiphertext,
                                string rawAuthenticationTag)
        {
            if (header == null)
            {
                throw LogHelper.LogArgumentNullException(nameof(header));
            }

            if (innerToken == null)
            {
                throw LogHelper.LogArgumentNullException(nameof(innerToken));
            }

            if (rawEncryptedKey == null)
            {
                throw LogHelper.LogArgumentNullException(nameof(rawEncryptedKey));
            }

            if (string.IsNullOrEmpty(rawInitializationVector))
            {
                throw LogHelper.LogArgumentNullException(nameof(rawInitializationVector));
            }

            if (string.IsNullOrEmpty(rawCiphertext))
            {
                throw LogHelper.LogArgumentNullException(nameof(rawCiphertext));
            }

            if (string.IsNullOrEmpty(rawAuthenticationTag))
            {
                throw LogHelper.LogArgumentNullException(nameof(rawAuthenticationTag));
            }

            Header                  = header;
            InnerToken              = innerToken;
            RawData                 = string.Join(".", rawHeader, rawEncryptedKey, rawInitializationVector, rawCiphertext, rawAuthenticationTag);
            RawHeader               = rawHeader;
            RawEncryptedKey         = rawEncryptedKey;
            RawInitializationVector = rawInitializationVector;
            RawCiphertext           = rawCiphertext;
            RawAuthenticationTag    = rawAuthenticationTag;
        }
コード例 #3
0
        /// <summary>
        /// Decodes the string into the header, payload and signature.
        /// </summary>
        /// <param name="tokenParts">the tokenized string.</param>
        /// <param name="rawData">the original token.</param>
        internal void Decode(string[] tokenParts, string rawData)
        {
            IdentityModelEventSource.Logger.WriteInformation(LogMessages.IDX10716, rawData);
            try
            {
                Header = JwtHeader.Base64UrlDeserialize(tokenParts[0]);
            }
            catch (Exception ex)
            {
                throw LogHelper.LogExceptionMessage(new ArgumentException(String.Format(CultureInfo.InvariantCulture, LogMessages.IDX10729, tokenParts[0], rawData), ex));
            }

            if (tokenParts.Length == JwtConstants.JweSegmentCount)
            {
                DecodeJwe(tokenParts);
            }
            else
            {
                DecodeJws(tokenParts);
            }

            RawData = rawData;
        }