mirror of https://github.com/usbharu/Hideout.git
feat: トークン、リフレッシュトークンの発行とリフレッシュトークンからトークンの再生成ができるように
This commit is contained in:
parent
749f0c891d
commit
5c82bfd532
|
@ -101,7 +101,8 @@ fun Application.parent() {
|
|||
inject<IUserAuthService>().value,
|
||||
inject<IMetaRepository>().value,
|
||||
inject<IJwtRefreshTokenRepository>().value,
|
||||
inject<IUserRepository>().value
|
||||
inject<IUserRepository>().value,
|
||||
inject<IdGenerateService>().value
|
||||
)
|
||||
configureRouting(
|
||||
inject<HttpSignatureVerifyService>().value,
|
||||
|
|
|
@ -107,14 +107,14 @@ fun Application.configureSecurity(
|
|||
post("/refresh-token") {
|
||||
val refreshToken = call.receive<RefreshToken>()
|
||||
val findByToken = refreshTokenRepository.findByToken(refreshToken.refreshToken)
|
||||
?: return@post call.respond(HttpStatusCode.Forbidden)
|
||||
?: return@post call.respondText("token not found",status = HttpStatusCode.Forbidden)
|
||||
|
||||
if (findByToken.createdAt.isAfter(Instant.now())) {
|
||||
return@post call.respond(HttpStatusCode.Forbidden)
|
||||
return@post call.respondText("created_at", status = HttpStatusCode.Forbidden)
|
||||
}
|
||||
|
||||
if (findByToken.expiresAt.isAfter(Instant.now())) {
|
||||
return@post call.respond(HttpStatusCode.Forbidden)
|
||||
if (findByToken.expiresAt.isBefore(Instant.now())) {
|
||||
return@post call.respondText( "expires_at", status = HttpStatusCode.Forbidden)
|
||||
}
|
||||
|
||||
val user = userRepository.findById(findByToken.userId)
|
||||
|
|
|
@ -18,13 +18,24 @@ export const App: Component = () => {
|
|||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}).then(res => res.text())
|
||||
.then(res => fetch("/auth-check", {
|
||||
method: "GET",
|
||||
}).then(res => res.json())
|
||||
// .then(res => fetch("/auth-check", {
|
||||
// method: "GET",
|
||||
// headers: {
|
||||
// 'Authorization': 'Bearer ' + res.token
|
||||
// }
|
||||
// }))
|
||||
// .then(res => res.json())
|
||||
.then(res => {
|
||||
console.log(res.token);
|
||||
fetch("/refresh-token", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + res
|
||||
}
|
||||
})).then(res => console.log(res))
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({refreshToken: res.refreshToken}),
|
||||
}).then(res=> res.json()).then(res => console.log(res.token))
|
||||
})
|
||||
}
|
||||
|
||||
}>
|
||||
|
|
|
@ -10,6 +10,7 @@ export default defineConfig({
|
|||
'/api': 'http://localhost:8080',
|
||||
'/login': 'http://localhost:8080',
|
||||
'/auth-check': 'http://localhost:8080',
|
||||
'/refresh-token': 'http://localhost:8080',
|
||||
}
|
||||
},
|
||||
root: './src/main/web',
|
||||
|
|
Loading…
Reference in New Issue