Skip to content

Commit fe1dddc

Browse files
committed
feat(yogurt): add logging on auth failing paths
close #60
1 parent 7d4bf25 commit fe1dddc

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

  • acidify-milky/src/commonMain/kotlin/org/ntqqrev/acidify/milky

acidify-milky/src/commonMain/kotlin/org/ntqqrev/acidify/milky/api/Auth.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import org.ntqqrev.acidify.milky.MilkyContext
99
context(ctx: MilkyContext)
1010
fun Route.apiAuth() = install(createRouteScopedPlugin("ApiAuth") {
1111
onCall { call ->
12+
val logger = ctx.bot.createLogger("ApiAuthPlugin")
1213
if (call.request.headers["Authorization"] != "Bearer ${ctx.httpAccessToken}") {
14+
logger.i { "${call.request.local.remoteAddress} 未携带正确的 access token,拒绝访问" }
1315
call.respond(HttpStatusCode.Unauthorized)
1416
return@onCall
1517
}

acidify-milky/src/commonMain/kotlin/org/ntqqrev/acidify/milky/event/Auth.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import org.ntqqrev.acidify.milky.MilkyContext
99
context(ctx: MilkyContext)
1010
fun Route.eventAuth() = install(createRouteScopedPlugin("EventAuth") {
1111
onCall { call ->
12+
val logger = ctx.bot.createLogger("ApiAuthPlugin")
1213
if (
1314
call.request.headers["Authorization"] != "Bearer ${ctx.httpAccessToken}" &&
1415
call.request.queryParameters["access_token"] != ctx.httpAccessToken
1516
) {
17+
logger.i { "${call.request.local.remoteAddress} 未携带正确的 access token,拒绝访问" }
1618
call.respond(HttpStatusCode.Unauthorized)
1719
return@onCall
1820
}

0 commit comments

Comments
 (0)