Add code from the meeting.

This commit is contained in:
Kavin 2023-10-29 21:26:42 +00:00
parent 470efd8068
commit 5f6a83aa73
No known key found for this signature in database
GPG key ID: 6E4598CA5C92C41F
2 changed files with 30 additions and 1 deletions

View file

@ -19,6 +19,7 @@ import me.kavin.piped.utils.ExceptionHandler;
import me.kavin.piped.utils.RequestUtils;
import me.kavin.piped.utils.obj.OidcData;
import me.kavin.piped.utils.obj.OidcProvider;
import me.kavin.piped.utils.obj.db.OidcUserData;
import me.kavin.piped.utils.obj.db.User;
import me.kavin.piped.utils.resp.*;
import org.apache.commons.codec.digest.DigestUtils;
@ -297,6 +298,14 @@ public class UserHandlers {
String hash = user.getPassword();
if (hash.isEmpty()) {
CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<OidcUserData> cr = cb.createQuery(OidcUserData.class);
Root<OidcUserData> root = cr.from(OidcUserData.class);
cr.select(root).where(cb.equal(root.get("user"), user.getId()));
OidcUserData oidcUserData = s.createQuery(cr).uniqueResult();
//TODO: Get user from oidc table and lookup provider
OidcProvider provider = Constants.OIDC_PROVIDERS.get(0);
URI callback = URI.create(String.format("%s/oidc/%s/delete", Constants.PUBLIC_URL, provider.name));
@ -310,7 +319,8 @@ public class UserHandlers {
.state(new State(state)).nonce(data.nonce).maxAge(0).build();
return String.format("{\"redirect\": \"%s\"}", oidcRequest.toURI().toString()).getBytes();
return mapper.writeValueAsBytes(mapper.createObjectNode()
.put("redirect", oidcRequest.toURI().toString()));
}
if (!hashMatch(hash, pass))
ExceptionHandler.throwErrorResponse(new IncorrectCredentialsResponse());

View file

@ -0,0 +1,19 @@
package me.kavin.piped.utils.obj.db;
import jakarta.persistence.*;
@Entity
@Table(name = "oidc_user_data")
public class OidcUserData {
@Column(unique = true)
@Id
private String sub;
@OneToOne
private User user;
private String provider;
}