mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-01-08 18:40:29 +05:30
Simplify oidc hash generation.
This commit is contained in:
parent
074e4bc136
commit
580eb7fbbe
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user