diff --git a/src/main/java/me/kavin/piped/utils/obj/OidcData.java b/src/main/java/me/kavin/piped/utils/obj/OidcData.java index 6275876..1db4ed4 100644 --- a/src/main/java/me/kavin/piped/utils/obj/OidcData.java +++ b/src/main/java/me/kavin/piped/utils/obj/OidcData.java @@ -2,14 +2,11 @@ package me.kavin.piped.utils.obj; import com.nimbusds.oauth2.sdk.pkce.CodeVerifier; import com.nimbusds.openid.connect.sdk.Nonce; -import com.nimbusds.openid.connect.sdk.validators.IDTokenValidator; - -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Base64; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.digest.DigestUtils; public class OidcData { + public final Nonce nonce; public final CodeVerifier pkceVerifier; public final String data; @@ -21,19 +18,13 @@ public class OidcData { } public boolean validateNonce(String nonce) { - return this.nonce.toString().equals(nonce); + return this.nonce.getValue().equals(nonce); } public String getState() { String value = nonce + data; - try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - byte[] hash = md.digest(value.getBytes(StandardCharsets.UTF_8)); - return Base64.getEncoder().encodeToString(hash); - - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("SHA-256 not supported", e); - } + byte[] hash = DigestUtils.sha256(value); + return Base64.encodeBase64String(hash); } }