mirror of https://github.com/usbharu/Hideout.git
feat: usernameからuidに変更
This commit is contained in:
parent
736f83e3e1
commit
69c0a8692f
|
@ -35,11 +35,14 @@ fun Application.configureSecurity(
|
||||||
acceptLeeway(3)
|
acceptLeeway(3)
|
||||||
}
|
}
|
||||||
validate { jwtCredential ->
|
validate { jwtCredential ->
|
||||||
if (jwtCredential.payload.getClaim("username")?.asString().isNullOrBlank().not()) {
|
val uid = jwtCredential.payload.getClaim("uid")
|
||||||
JWTPrincipal(jwtCredential.payload)
|
if (uid.isMissing) {
|
||||||
} else {
|
return@validate null
|
||||||
null
|
|
||||||
}
|
}
|
||||||
|
if (uid.asLong() == null) {
|
||||||
|
return@validate null
|
||||||
|
}
|
||||||
|
return@validate JWTPrincipal(jwtCredential.payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +77,7 @@ fun Application.configureSecurity(
|
||||||
authenticate(TOKEN_AUTH) {
|
authenticate(TOKEN_AUTH) {
|
||||||
get("/auth-check") {
|
get("/auth-check") {
|
||||||
val principal = call.principal<JWTPrincipal>()
|
val principal = call.principal<JWTPrincipal>()
|
||||||
val username = principal!!.payload.getClaim("username")
|
val username = principal!!.payload.getClaim("uid")
|
||||||
call.respondText("Hello $username")
|
call.respondText("Hello $username")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,7 @@ class SecurityKtTest {
|
||||||
.withAudience("${Config.configData.url}/users/test")
|
.withAudience("${Config.configData.url}/users/test")
|
||||||
.withIssuer(Config.configData.url)
|
.withIssuer(Config.configData.url)
|
||||||
.withKeyId(kid.toString())
|
.withKeyId(kid.toString())
|
||||||
.withClaim("username", "test")
|
.withClaim("uid", 123456L)
|
||||||
.withExpiresAt(now.plus(30, ChronoUnit.MINUTES))
|
.withExpiresAt(now.plus(30, ChronoUnit.MINUTES))
|
||||||
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
||||||
val metaService = mock<IMetaService> {
|
val metaService = mock<IMetaService> {
|
||||||
|
@ -255,7 +255,7 @@ class SecurityKtTest {
|
||||||
header("Authorization", "Bearer $token")
|
header("Authorization", "Bearer $token")
|
||||||
}.apply {
|
}.apply {
|
||||||
assertEquals(HttpStatusCode.OK, call.response.status)
|
assertEquals(HttpStatusCode.OK, call.response.status)
|
||||||
assertEquals("Hello \"test\"", call.response.bodyAsText())
|
assertEquals("Hello 123456", call.response.bodyAsText())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ class SecurityKtTest {
|
||||||
.withAudience("${Config.configData.url}/users/test")
|
.withAudience("${Config.configData.url}/users/test")
|
||||||
.withIssuer(Config.configData.url)
|
.withIssuer(Config.configData.url)
|
||||||
.withKeyId(kid.toString())
|
.withKeyId(kid.toString())
|
||||||
.withClaim("username", "test")
|
.withClaim("uid", 123345L)
|
||||||
.withExpiresAt(now.minus(30, ChronoUnit.MINUTES))
|
.withExpiresAt(now.minus(30, ChronoUnit.MINUTES))
|
||||||
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
||||||
val metaService = mock<IMetaService> {
|
val metaService = mock<IMetaService> {
|
||||||
|
@ -335,7 +335,7 @@ class SecurityKtTest {
|
||||||
.withAudience("${Config.configData.url}/users/test")
|
.withAudience("${Config.configData.url}/users/test")
|
||||||
.withIssuer("https://example.com")
|
.withIssuer("https://example.com")
|
||||||
.withKeyId(kid.toString())
|
.withKeyId(kid.toString())
|
||||||
.withClaim("username", "test")
|
.withClaim("uid", 12345L)
|
||||||
.withExpiresAt(now.plus(30, ChronoUnit.MINUTES))
|
.withExpiresAt(now.plus(30, ChronoUnit.MINUTES))
|
||||||
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
||||||
val metaService = mock<IMetaService> {
|
val metaService = mock<IMetaService> {
|
||||||
|
@ -393,7 +393,7 @@ class SecurityKtTest {
|
||||||
.withAudience("${Config.configData.url}/users/test")
|
.withAudience("${Config.configData.url}/users/test")
|
||||||
.withIssuer(Config.configData.url)
|
.withIssuer(Config.configData.url)
|
||||||
.withKeyId(kid.toString())
|
.withKeyId(kid.toString())
|
||||||
.withClaim("username", "")
|
.withClaim("uid", null as Long?)
|
||||||
.withExpiresAt(now.plus(30, ChronoUnit.MINUTES))
|
.withExpiresAt(now.plus(30, ChronoUnit.MINUTES))
|
||||||
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
.sign(Algorithm.RSA256(rsaPublicKey, keyPair.private as RSAPrivateKey))
|
||||||
val metaService = mock<IMetaService> {
|
val metaService = mock<IMetaService> {
|
||||||
|
|
Loading…
Reference in New Issue