This commit is contained in:
jeffcheasey88
2023-10-13 15:00:19 +02:00
parent ddddcadb24
commit 5ad774abd2
7 changed files with 213 additions and 21 deletions

View File

@@ -2,8 +2,13 @@ package be.jeffcheasey88.todo;
import static dev.peerat.framework.RequestType.OPTIONS;
import java.io.File;
import java.util.regex.Matcher;
import org.jose4j.lang.JoseException;
import be.jeffcheasey88.todo.model.JsonRepository;
import be.jeffcheasey88.todo.model.UserWorker;
import be.jeffcheasey88.todo.routes.users.Login;
import dev.peerat.framework.Context;
import dev.peerat.framework.HttpReader;
@@ -16,13 +21,13 @@ import dev.peerat.framework.Router;
public class Main {
public static void main(String[] args) throws Exception {
Router<User> router = new Router<User>().configureJwt(
Router<UserWorker> router = new Router<UserWorker>().configureJwt(
(builder) -> builder.setExpectedIssuer("http://localhost"),
(claims) -> {
claims.setIssuer("http://localhost"); // who creates the token and signs it
claims.setExpirationTimeMinutesInTheFuture(100);
},
(claims) -> new User(claims))
(claims) -> new UserWorker(claims))
.addDefaultHeaders(RequestType.GET, "Access-Control-Allow-Origin: *")
.addDefaultHeaders(RequestType.POST, "Access-Control-Allow-Origin: *");
@@ -43,7 +48,14 @@ public class Main {
}
});
router.register(new Login(router));
JsonRepository json = new JsonRepository(new File("/home/todo/"), (username) -> {
try{
return router.createAuthUser(new UserWorker(username));
}catch(JoseException e){}
return null;
});
router.register(new Login(json));
router.listen(80, false);
}