getCodeChallenge(); $code_challenge_method = $auth_code->getCodeChallengeMethod(); if(empty($code_challenge) || empty($code_challenge_method)){ throw new InvalidOAuth2PKCERequest(sprintf("%s or %s missing", OAuth2Protocol::PKCE_CodeChallenge, OAuth2Protocol::PKCE_CodeChallengeMethod)); } /** * code_verifier = high-entropy cryptographic random STRING using the * unreserved characters [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~" * from Section 2.3 of [RFC3986], with a minimum length of 43 characters * and a maximum length of 128 characters. */ $code_verifier = $request->getCodeVerifier(); if(empty($code_verifier)) throw new InvalidOAuth2PKCERequest(sprintf("%s param required", OAuth2Protocol::PKCE_CodeVerifier)); $code_verifier_len = strlen($code_verifier); if( $code_verifier_len < 43 || $code_verifier_len > 128) throw new InvalidOAuth2PKCERequest(sprintf("%s param should have at least 43 and at most 128 characters.", OAuth2Protocol::PKCE_CodeVerifier)); switch ($code_challenge_method){ case OAuth2Protocol::PKCE_CodeChallengeMethodPlain: return new PKCEPlainValidator($code_challenge, $code_verifier); break; case OAuth2Protocol::PKCE_CodeChallengeMethodSHA256: return new PKCES256Validator($code_challenge, $code_verifier); break; default: throw new InvalidOAuth2PKCERequest(sprintf("invalid %s param", OAuth2Protocol::PKCE_CodeChallengeMethod)); break; } } }