Change naming
This commit is contained in:
parent
644d065ec9
commit
8cb223e862
3 changed files with 17 additions and 12 deletions
|
@ -36,7 +36,6 @@ void main(List<String> argsRaw) async {
|
||||||
..get("/userinfo", apiHelper.userinfoHandler)
|
..get("/userinfo", apiHelper.userinfoHandler)
|
||||||
..get("/bridge", apiHelper.bridgeHandler)
|
..get("/bridge", apiHelper.bridgeHandler)
|
||||||
..post("/login", apiHelper.loginHandler)
|
..post("/login", apiHelper.loginHandler)
|
||||||
..post("/introspect", apiHelper.introspectionHandler)
|
|
||||||
..post("/logout", apiHelper.logoutHandler)
|
..post("/logout", apiHelper.logoutHandler)
|
||||||
..post("/token", apiHelper.tokenHandler))
|
..post("/token", apiHelper.tokenHandler))
|
||||||
.call,
|
.call,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import "package:dart_jsonwebtoken/dart_jsonwebtoken.dart";
|
||||||
import "package:matrixoidc/controllers/auth_code_controller.dart";
|
import "package:matrixoidc/controllers/auth_code_controller.dart";
|
||||||
import "package:matrixoidc/controllers/key_controller.dart";
|
import "package:matrixoidc/controllers/key_controller.dart";
|
||||||
import "package:matrixoidc/controllers/settings_controller.dart";
|
import "package:matrixoidc/controllers/settings_controller.dart";
|
||||||
import "package:matrixoidc/helpers/name_helper.dart";
|
|
||||||
import "package:shelf/shelf.dart";
|
import "package:shelf/shelf.dart";
|
||||||
import "package:http/http.dart" as http;
|
import "package:http/http.dart" as http;
|
||||||
import "package:matrixoidc/models/matrix_user.dart";
|
import "package:matrixoidc/models/matrix_user.dart";
|
||||||
|
@ -126,7 +125,6 @@ class ApiHelper {
|
||||||
"exp":
|
"exp":
|
||||||
DateTime.now().add(Duration(days: 7)).millisecondsSinceEpoch ~/
|
DateTime.now().add(Duration(days: 7)).millisecondsSinceEpoch ~/
|
||||||
1000,
|
1000,
|
||||||
"name": user.userId.getName(),
|
|
||||||
"nonce": user.nonce,
|
"nonce": user.nonce,
|
||||||
"iat": DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
"iat": DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||||
},
|
},
|
||||||
|
@ -163,7 +161,21 @@ class ApiHelper {
|
||||||
await ref.read(KeyController.provider.future),
|
await ref.read(KeyController.provider.future),
|
||||||
);
|
);
|
||||||
|
|
||||||
final name = jwt.subject!.getName();
|
final settings = ref.read(SettingsController.provider)!;
|
||||||
|
final profile = await http.get(
|
||||||
|
Uri.parse(
|
||||||
|
"${settings.homeserver}/_matrix/client/v3/profile/${jwt.subject}",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (profile.statusCode != 200) {
|
||||||
|
return Response.forbidden(
|
||||||
|
json.encode({"error": "Access token validation failed"}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final name = json.decode(profile.body)["displayname"];
|
||||||
|
|
||||||
return Response.ok(
|
return Response.ok(
|
||||||
jsonEncode({
|
jsonEncode({
|
||||||
"sub": jwt.subject,
|
"sub": jwt.subject,
|
||||||
|
@ -185,13 +197,10 @@ class ApiHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final jwt = JWT.verify(
|
JWT.verify(token, await ref.read(KeyController.provider.future));
|
||||||
token,
|
|
||||||
await ref.read(KeyController.provider.future),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Response.ok(
|
return Response.ok(
|
||||||
json.encode({"active": true, "name": jwt.subject!.getName()}),
|
json.encode({"active": true}),
|
||||||
headers: {"content-type": "application/json"},
|
headers: {"content-type": "application/json"},
|
||||||
);
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
extension GetName on String {
|
|
||||||
String getName() => split(":").first.replaceFirst("@", "");
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue