diff --git a/.vscode/launch.json b/.vscode/launch.json index 380f43f..280503b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,7 @@ "--jwtSecretFile", "secret", "--issuer", - "http://localhost:8080/", + "http://localhost:8080", "--authorizeEndpoint", "http://localhost:4321/login", "--serviceDomain", diff --git a/JUSTFILE b/JUSTFILE index c2d7582..0a86649 100644 --- a/JUSTFILE +++ b/JUSTFILE @@ -5,4 +5,4 @@ build: dart run build_runner build test: - oauth2c http://localhost:8080 --client-id yourclientid --redirect-url http://localhost:8081/callback --scopes openid --grant-type authorization_code --auth-method none --response-mode query \ No newline at end of file + oauth2c http://localhost:8080 --client-id yourclientid --scopes openid --grant-type authorization_code --auth-method none --response-mode query \ No newline at end of file diff --git a/lib/helpers/api_helper.dart b/lib/helpers/api_helper.dart index b59d73b..256dc3d 100644 --- a/lib/helpers/api_helper.dart +++ b/lib/helpers/api_helper.dart @@ -23,7 +23,7 @@ class ApiHelper { final state = data["state"] ?? ""; if (userId == null || accessToken == null || redirectUri == null) { - return Response(400, body: "Missing parameters"); + return Response(400, body: json.encode({"error": "Missing parameters"})); } final settings = ref.read(SettingsController.provider)!; @@ -33,7 +33,9 @@ class ApiHelper { ); if (whoamiRes.statusCode != 200) { - return Response.forbidden("Access token validation failed"); + return Response.forbidden( + json.encode({"error": "Access token validation failed"}), + ); } final code = base64Url.encode( @@ -71,7 +73,10 @@ class ApiHelper { final redirectUri = query["redirect_uri"]; if (code == null || redirectUri == null) { - return Response(400, body: "Missing code or redirect_uri"); + return Response( + 400, + body: json.encode({"error": "Missing code or redirect_uri"}), + ); } final tokenRes = await tokenHandler( @@ -83,7 +88,7 @@ class ApiHelper { ); if (tokenRes.statusCode != 200) { - return Response(400, body: "Token post failed"); + return Response(400, body: json.encode({"error": "Token post failed"})); } return Response.found( @@ -102,12 +107,15 @@ class ApiHelper { final clientId = body["client_id"]; if (code == null || clientId == null) { - return Response(400, body: "Missing code or client_id"); + return Response( + 400, + body: json.encode({"error": "Missing code or client_id"}), + ); } final codes = ref.read(AuthCodeController.provider); if (!codes.containsKey(code)) { - return Response(400, body: "Invalid code"); + return Response(400, body: json.encode({"error": "Invalid code"})); } final user = codes[code]!; @@ -173,7 +181,9 @@ class ApiHelper { Future introspectionHandler(Request request) async { final token = Uri.splitQueryString(await request.readAsString())["token"]; - if (token == null) return Response(400, body: "Missing token"); + if (token == null) { + return Response(400, body: json.encode({"error": "Missing token"})); + } try { JWT.verify( @@ -213,7 +223,7 @@ class ApiHelper { } Future logoutHandler(Request request) async => - Response.ok("Log out is not currently implemented"); + Response.ok(json.encode("Log out is not currently implemented")); Response openidConfiguration(_) { final settings = ref.read(SettingsController.provider)!; diff --git a/lib/helpers/name_helper.dart b/lib/helpers/name_helper.dart index 79a70d2..76c0460 100644 --- a/lib/helpers/name_helper.dart +++ b/lib/helpers/name_helper.dart @@ -1,3 +1,3 @@ extension GetName on String { - String getName() => split(":")[1].replaceFirst("@", ""); + String getName() => split(":").first.replaceFirst("@", ""); }