public PKCE Build(CodeChallengeMethods method)
        {
            var result = new PKCE();

            result.CodeVerifier  = GetCodeVerifier();
            result.CodeChallenge = GetCodeChallenge(result.CodeVerifier, method);
            return(result);
        }
Example #2
0
        /// <summary>
        /// Gets the string respresentation of a <see cref="CodeChallengeMethods"/>.
        /// </summary>
        /// <param name="codeChallengeMethod">The <see cref="CodeChallengeMethods"/>.</param>
        /// <returns>A <see cref="string"/> representing the <see cref="CodeChallengeMethods"/>.</returns>
        public static string ParseCodeChallengeMethod(CodeChallengeMethods codeChallengeMethod)
        {
            string result = string.Empty;

            if (codeChallengeMethod == CodeChallengeMethods.S256)
            {
                result = "S256";
            }

            return(result);
        }
        private static string GetCodeChallenge(string codeVerifier, CodeChallengeMethods method)
        {
            if (method == CodeChallengeMethods.Plain)
            {
                return(codeVerifier);
            }

            var hashed = SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(codeVerifier));

            return(hashed.Base64EncodeBytes());
        }
Example #4
0
        /// <summary>
        /// Gets the string respresentation of a <see cref="CodeChallengeMethods"/>.
        /// </summary>
        /// <param name="codeChallengeMethod">The <see cref="CodeChallengeMethods"/>.</param>
        /// <returns>A <see cref="string"/> representing the <see cref="CodeChallengeMethods"/>.</returns>
        public static string ParseCodeChallengeMethod(CodeChallengeMethods codeChallengeMethod)
        {
            string result = string.Empty;

            switch (codeChallengeMethod)
            {
            case CodeChallengeMethods.S256:
                result = "S256";
                break;
            }

            return(result);
        }