Код: Выделить всё
{"error":"invalid_grant","error_description":"code_verifier is invalid"}
Код: Выделить всё
@Override
public String getOAuth2AuthorizationUrl() {
String sha256hex = null;
try {
if(_currentVerifier == null)
_currentVerifier = PkceUtil.generateCodeVerifier();
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] encodedhash = digest.digest(
_currentVerifier.getBytes(StandardCharsets.UTF_8));
sha256hex = new String(encodedhash);
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
UnicodeEscaper basicEscaper = new PercentEscaper("-", false);
System.out.println("sha256="+sha256hex);
System.out.println("veri="+_currentVerifier);
String oAuth2AuthorizationUrl = super.getOAuth2AuthorizationUrl();
var authUrl = oAuth2AuthorizationUrl
+"&state=asdf&code_challenge_method=S256&code_challenge='"
+ basicEscaper.escape(sha256hex)+"'";
return authUrl;
}
Код: Выделить всё
UnicodeEscaper basicEscaper = new PercentEscaper("-", false);
var params = "grant_type=authorization_code&client_id="
+token.getOwner().clientId+"&redirect_uri="
+basicEscaper.escape("https://localhost")
+"&code="+accessCode+"&code_verifier="+basicEscaper.escape(_currentVerifier)+"";
Есть идеи?
Обновление:
Я попробовал использовать библиотеку Google для генерации хеша, но все равно получаю ту же ошибку.
Код: Выделить всё
Hasher hasher = Hashing.sha256().newHasher();
hasher.putString(CODE_VERIFIER, Charsets.UTF_8);
HashCode sha256 = hasher.hash();
System.out.println("veri="+AppUtils.encodeBase64(AppUtils.toHexString(sha256.asBytes())));
String oAuth2AuthorizationUrl = super.getOAuth2AuthorizationUrl();
var authUrl = oAuth2AuthorizationUrl
+"&state=asdf&code_challenge_method=S256&code_challenge="+AppUtils.encodeBase64(AppUtils.toHexString(sha256.asBytes()));
return authUrl;
Подробнее здесь: https://stackoverflow.com/questions/697 ... is-invalid