mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-01-09 11:00: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.oauth2.sdk.pkce.CodeVerifier;
|
||||||
import com.nimbusds.openid.connect.sdk.Nonce;
|
import com.nimbusds.openid.connect.sdk.Nonce;
|
||||||
import com.nimbusds.openid.connect.sdk.validators.IDTokenValidator;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
public class OidcData {
|
public class OidcData {
|
||||||
|
|
||||||
public final Nonce nonce;
|
public final Nonce nonce;
|
||||||
public final CodeVerifier pkceVerifier;
|
public final CodeVerifier pkceVerifier;
|
||||||
public final String data;
|
public final String data;
|
||||||
@ -21,19 +18,13 @@ public class OidcData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateNonce(String nonce) {
|
public boolean validateNonce(String nonce) {
|
||||||
return this.nonce.toString().equals(nonce);
|
return this.nonce.getValue().equals(nonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
public String getState() {
|
||||||
String value = nonce + data;
|
String value = nonce + data;
|
||||||
|
|
||||||
try {
|
byte[] hash = DigestUtils.sha256(value);
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
return Base64.encodeBase64String(hash);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user