Skip to content

Commit 5b68fa1

Browse files
committed
Include message when unauthorized
1 parent b3ff7f2 commit 5b68fa1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

oauth2-server-core/src/main/java/nl/myndocs/oauth2/CallRouter.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class CallRouter(
2828

2929
const val STATUS_BAD_REQUEST = 400
3030
const val STATUS_UNAUTHORIZED = 401
31+
32+
private val unauthorizedResponse = mapOf("message" to "anauthorized")
3133
}
3234

3335
fun route(callContext: CallContext) {
@@ -99,7 +101,7 @@ class CallRouter(
99101

100102
return RedirectRouterResponse(true)
101103
} catch (unverifiedIdentityException: InvalidIdentityException) {
102-
callContext.respondStatus(STATUS_UNAUTHORIZED)
104+
callContext.respondUnauthorized()
103105

104106
return RedirectRouterResponse(false)
105107
}
@@ -134,7 +136,7 @@ class CallRouter(
134136

135137
return RedirectRouterResponse(true)
136138
} catch (unverifiedIdentityException: InvalidIdentityException) {
137-
callContext.respondStatus(STATUS_UNAUTHORIZED)
139+
callContext.respondUnauthorized()
138140

139141
return RedirectRouterResponse(false)
140142
}
@@ -174,7 +176,7 @@ class CallRouter(
174176
val authorization = callContext.headerCaseInsensitive("Authorization")
175177

176178
if (authorization == null || !authorization.startsWith("bearer ", true)) {
177-
callContext.respondStatus(STATUS_UNAUTHORIZED)
179+
callContext.respondUnauthorized()
178180
return
179181
}
180182

@@ -183,4 +185,9 @@ class CallRouter(
183185

184186
callContext.respondJson(tokenInfoCallback)
185187
}
188+
189+
private fun CallContext.respondUnauthorized() {
190+
this.respondStatus(STATUS_UNAUTHORIZED)
191+
this.respondJson(unauthorizedResponse)
192+
}
186193
}

0 commit comments

Comments
 (0)