mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Add code from the meeting.
This commit is contained in:
parent
470efd8068
commit
5f6a83aa73
2 changed files with 30 additions and 1 deletions
|
@ -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());
|
||||
|
|
19
src/main/java/me/kavin/piped/utils/obj/db/OidcUserData.java
Normal file
19
src/main/java/me/kavin/piped/utils/obj/db/OidcUserData.java
Normal 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;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue