feat: トークン、リフレッシュトークンの発行とリフレッシュトークンからトークンの再生成ができるように

This commit is contained in:
usbharu 2023-05-02 08:48:23 +09:00
parent 749f0c891d
commit 5c82bfd532
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
4 changed files with 24 additions and 11 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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))
})
}
}>

View File

@ -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',