Ejemplo n.º 1
0
        public ActionResult AuthorizationCode_PKCE_S256()
        {
            this.Init();
            this.CodeVerifier  = GetPassword.Base64UrlSecret(50);
            this.CodeChallenge = OAuth2Helper.PKCE_S256_CodeChallengeMethod(this.CodeVerifier);
            this.Save();

            // Authorization Code Flow (PKCE S256)
            return(Redirect(this.AssembleOAuth2Starter(
                                ASPNETIdentityConst.AuthorizationCodeResponseType)
                            + "&code_challenge=" + this.CodeChallenge
                            + "&code_challenge_method=S256"));
        }
Ejemplo n.º 2
0
        /// <summary>VerifyCodeVerifier</summary>
        /// <param name="value">string</param>
        /// <param name="code_verifier">string</param>
        /// <returns>ticket</returns>
        private string VerifyCodeVerifier(string value, string code_verifier)
        {
            // null チェック
            if (string.IsNullOrEmpty(value))
            {
                return("");
            }

            Dictionary <string, string> temp = JsonConvert.DeserializeObject <Dictionary <string, string> >(value);

            bool isPKCE = (code_verifier != null);

            if (!isPKCE)
            {
                // 通常のアクセストークン・リクエスト
                if (string.IsNullOrEmpty(temp["code_challenge"]))
                {
                    // Authorization Codeのcode
                    return(temp["ticket"]);
                }
                else
                {
                    // OAuth PKCEのcode(要 code_verifier)
                    return("");
                }
            }
            else
            {
                // OAuth PKCEのアクセストークン・リクエスト
                if (!string.IsNullOrEmpty(temp["code_challenge"]) && !string.IsNullOrEmpty(code_verifier))
                {
                    if (temp["code_challenge_method"].ToLower() == "plain")
                    {
                        // plain
                        if (temp["code_challenge"] == code_verifier)
                        {
                            // 検証成功
                            return(temp["ticket"]);
                        }
                        else
                        {
                            // 検証失敗
                        }
                    }
                    else if (temp["code_challenge_method"].ToLower() == "s256")
                    {
                        // s256
                        if (temp["code_challenge"] == OAuth2Helper.PKCE_S256_CodeChallengeMethod(code_verifier))
                        {
                            // 検証成功
                            return(temp["ticket"]);
                        }
                        else
                        {
                            // 検証失敗
                        }
                    }
                    else
                    {
                        // パラメタ不正
                    }
                }
                else
                {
                    // パラメタ不正
                }

                return(null);
            }
        }