/// <summary>
        /// Parses the id token and constructs the IdToken class.
        /// </summary>
        /// <param name="idToken">The string to pass.</param>
        /// <returns>The instance of the class.</returns>
        public static IdToken Parse(string idToken)
        {
            if (string.IsNullOrEmpty(idToken))
            {
                return(null);
            }

            string[] idTokenSegments = idToken.Split(new[] { '.' });

            if (idTokenSegments.Length < 2)
            {
                throw new AuthClientException(
                          AuthError.InvalidJwtError,
                          AuthErrorMessage.IDTokenMustHaveTwoParts);
            }

            try
            {
                var idTokenString = Base64UrlHelpers.DecodeToString(idTokenSegments[1]);
                return(JsonConvert.DeserializeObject <IdToken>(idTokenString));
            }
            catch (Exception exc)
            {
                throw new AuthClientException(
                          AuthError.JsonParseError,
                          AuthErrorMessage.FailedToParseIDToken,
                          exc);
            }
        }
        public string GenerateCodeVerifier()
        {
            byte[] buffer        = new byte[Constants.CodeVerifierByteSize];
            var    windowsBuffer = CryptographicBuffer.GenerateRandom((uint)buffer.Length);

            Array.Copy(windowsBuffer.ToArray(), buffer, buffer.Length);

            return(Base64UrlHelpers.Encode(buffer));
        }
Example #3
0
        public string GenerateCodeVerifier()
        {
            byte[] buffer = new byte[Constants.CodeVerifierByteSize];
            using (RNGCryptoServiceProvider randomSource = new RNGCryptoServiceProvider())
            {
                randomSource.GetBytes(buffer);
            }

            return(Base64UrlHelpers.Encode(buffer));
        }
Example #4
0
        public string GenerateCodeVerifier()
        {
            byte[] buffer = new byte[Constants.CodeVerifierByteSize];
            using (var randomSource = RandomNumberGenerator.Create())
            {
                randomSource.GetBytes(buffer);
            }

            return(Base64UrlHelpers.Encode(buffer));
        }
Example #5
0
        public string CreateBase64UrlEncodedSha256Hash(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(null);
            }

            using (SHA256Managed sha = new SHA256Managed())
            {
                UTF8Encoding encoding = new UTF8Encoding();
                return(Base64UrlHelpers.Encode(sha.ComputeHash(encoding.GetBytes(input))));
            }
        }
        public string CreateBase64UrlEncodedSha256Hash(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(null);
            }

            IBuffer inputBuffer = CryptographicBuffer.ConvertStringToBinary(input, BinaryStringEncoding.Utf8);
            var     hasher      = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);

            IBuffer hashed = hasher.HashData(inputBuffer);
            string  output = CryptographicBuffer.EncodeToBase64String(hashed);

            return(Base64UrlHelpers.Encode(Convert.FromBase64String(output)));
        }
        public static ClientInfo CreateFromJson(string clientInfo)
        {
            if (string.IsNullOrEmpty(clientInfo))
            {
                throw new AuthClientException(
                          AuthError.JsonParseError,
                          "client info is null");
            }

            try
            {
                return(JsonHelper.DeserializeFromJson <ClientInfo>(Base64UrlHelpers.DecodeToBytes(clientInfo)));
            }
            catch (Exception exc)
            {
                throw new AuthClientException(
                          AuthError.JsonParseError,
                          "Failed to parse the returned client info.",
                          exc);
            }
        }
 public string ToEncodedJson()
 {
     return(Base64UrlHelpers.Encode(JsonHelper.SerializeToJson <ClientInfo>(this)));
 }
Example #9
0
 public string CreateBase64UrlEncodedSha256Hash(string input)
 {
     return(string.IsNullOrEmpty(input) ? null : Base64UrlHelpers.Encode(CreateSha256HashBytes(input)));
 }