Add introspection endpoint
This commit is contained in:
parent
8efb087cdd
commit
53867e273b
2 changed files with 27 additions and 0 deletions
|
@ -36,6 +36,7 @@ void main(List<String> argsRaw) async {
|
|||
..get("/userinfo", apiHelper.userinfoHandler)
|
||||
..get("/bridge", apiHelper.bridgeHandler)
|
||||
..post("/login", apiHelper.loginHandler)
|
||||
..post('/introspect', apiHelper.introspectionHandler)
|
||||
..post("/logout", apiHelper.logoutHandler)
|
||||
..post("/token", apiHelper.tokenHandler))
|
||||
.call,
|
||||
|
|
|
@ -157,6 +157,31 @@ class ApiHelper {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Response> introspectionHandler(Request request) async {
|
||||
final token = Uri.splitQueryString(await request.readAsString())['token'];
|
||||
if (token == null) return Response(400, body: "Missing token");
|
||||
|
||||
try {
|
||||
JWT.verify(
|
||||
token,
|
||||
SecretKey(
|
||||
(await File.fromUri(
|
||||
Uri.file(ref.read(SettingsController.provider)!.jwtSecretFile),
|
||||
).readAsString()),
|
||||
),
|
||||
);
|
||||
return Response.ok(
|
||||
json.encode({'active': true}),
|
||||
headers: {'content-type': 'application/json'},
|
||||
);
|
||||
} catch (_) {
|
||||
return Response.ok(
|
||||
json.encode({'active': false}),
|
||||
headers: {'content-type': 'application/json'},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response> logoutHandler(Request request) async =>
|
||||
Response.ok("Log out is not currently implemented");
|
||||
|
||||
|
@ -168,6 +193,7 @@ class ApiHelper {
|
|||
"authorization_endpoint": settings.authorizeEndpoint,
|
||||
"token_endpoint": "${settings.issuer}/token",
|
||||
"userinfo_endpoint": "${settings.issuer}/userinfo",
|
||||
"introspection_endpoint": "${settings.issuer}/introspect",
|
||||
"end_session_endpoint": "${settings.issuer}/logout",
|
||||
"response_types_supported": ["code"],
|
||||
"subject_types_supported": ["public"],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue