Some fixes
This commit is contained in:
parent
afc555e66e
commit
43f59851b8
4 changed files with 21 additions and 11 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -13,7 +13,7 @@
|
||||||
"--jwtSecretFile",
|
"--jwtSecretFile",
|
||||||
"secret",
|
"secret",
|
||||||
"--issuer",
|
"--issuer",
|
||||||
"http://localhost:8080/",
|
"http://localhost:8080",
|
||||||
"--authorizeEndpoint",
|
"--authorizeEndpoint",
|
||||||
"http://localhost:4321/login",
|
"http://localhost:4321/login",
|
||||||
"--serviceDomain",
|
"--serviceDomain",
|
||||||
|
|
2
JUSTFILE
2
JUSTFILE
|
@ -5,4 +5,4 @@ build:
|
||||||
dart run build_runner build
|
dart run build_runner build
|
||||||
|
|
||||||
test:
|
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
|
oauth2c http://localhost:8080 --client-id yourclientid --scopes openid --grant-type authorization_code --auth-method none --response-mode query
|
|
@ -23,7 +23,7 @@ class ApiHelper {
|
||||||
final state = data["state"] ?? "";
|
final state = data["state"] ?? "";
|
||||||
|
|
||||||
if (userId == null || accessToken == null || redirectUri == null) {
|
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)!;
|
final settings = ref.read(SettingsController.provider)!;
|
||||||
|
@ -33,7 +33,9 @@ class ApiHelper {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (whoamiRes.statusCode != 200) {
|
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(
|
final code = base64Url.encode(
|
||||||
|
@ -71,7 +73,10 @@ class ApiHelper {
|
||||||
final redirectUri = query["redirect_uri"];
|
final redirectUri = query["redirect_uri"];
|
||||||
|
|
||||||
if (code == null || redirectUri == null) {
|
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(
|
final tokenRes = await tokenHandler(
|
||||||
|
@ -83,7 +88,7 @@ class ApiHelper {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (tokenRes.statusCode != 200) {
|
if (tokenRes.statusCode != 200) {
|
||||||
return Response(400, body: "Token post failed");
|
return Response(400, body: json.encode({"error": "Token post failed"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.found(
|
return Response.found(
|
||||||
|
@ -102,12 +107,15 @@ class ApiHelper {
|
||||||
final clientId = body["client_id"];
|
final clientId = body["client_id"];
|
||||||
|
|
||||||
if (code == null || clientId == null) {
|
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);
|
final codes = ref.read(AuthCodeController.provider);
|
||||||
if (!codes.containsKey(code)) {
|
if (!codes.containsKey(code)) {
|
||||||
return Response(400, body: "Invalid code");
|
return Response(400, body: json.encode({"error": "Invalid code"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
final user = codes[code]!;
|
final user = codes[code]!;
|
||||||
|
@ -173,7 +181,9 @@ class ApiHelper {
|
||||||
|
|
||||||
Future<Response> introspectionHandler(Request request) async {
|
Future<Response> introspectionHandler(Request request) async {
|
||||||
final token = Uri.splitQueryString(await request.readAsString())["token"];
|
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 {
|
try {
|
||||||
JWT.verify(
|
JWT.verify(
|
||||||
|
@ -213,7 +223,7 @@ class ApiHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> logoutHandler(Request request) async =>
|
Future<Response> logoutHandler(Request request) async =>
|
||||||
Response.ok("Log out is not currently implemented");
|
Response.ok(json.encode("Log out is not currently implemented"));
|
||||||
|
|
||||||
Response openidConfiguration(_) {
|
Response openidConfiguration(_) {
|
||||||
final settings = ref.read(SettingsController.provider)!;
|
final settings = ref.read(SettingsController.provider)!;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
extension GetName on String {
|
extension GetName on String {
|
||||||
String getName() => split(":")[1].replaceFirst("@", "");
|
String getName() => split(":").first.replaceFirst("@", "");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue