add bridge
This commit is contained in:
parent
7d729ccb76
commit
b7bd137e16
2 changed files with 35 additions and 1 deletions
|
@ -34,6 +34,7 @@ void main(List<String> argsRaw) async {
|
||||||
apiHelper.openidConfiguration,
|
apiHelper.openidConfiguration,
|
||||||
)
|
)
|
||||||
..get("/userinfo", apiHelper.userinfoHandler)
|
..get("/userinfo", apiHelper.userinfoHandler)
|
||||||
|
..get("/bridge", apiHelper.bridgeHandler)
|
||||||
..post("/login", apiHelper.handleLogin)
|
..post("/login", apiHelper.handleLogin)
|
||||||
..post("/token", apiHelper.tokenHandler))
|
..post("/token", apiHelper.tokenHandler))
|
||||||
.call,
|
.call,
|
||||||
|
|
|
@ -43,7 +43,13 @@ class ApiHelper {
|
||||||
.read(AuthCodeController.provider.notifier)
|
.read(AuthCodeController.provider.notifier)
|
||||||
.set(code, MatrixUser(userId: userId, matrixToken: accessToken));
|
.set(code, MatrixUser(userId: userId, matrixToken: accessToken));
|
||||||
|
|
||||||
return Response.found("$redirectUri?code=$code&state=$state");
|
final uri = Uri.parse(redirectUri);
|
||||||
|
|
||||||
|
return Response.found(
|
||||||
|
uri.replace(
|
||||||
|
queryParameters: {...uri.queryParameters, "code": code, "state": state},
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> tokenHandler(Request request) async {
|
Future<Response> tokenHandler(Request request) async {
|
||||||
|
@ -96,6 +102,33 @@ class ApiHelper {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Response> bridgeHandler(Request request) async {
|
||||||
|
final query = request.url.queryParameters;
|
||||||
|
final code = query['code'];
|
||||||
|
final redirectUri = query['redirect_uri'];
|
||||||
|
|
||||||
|
if (code == null || redirectUri == null) {
|
||||||
|
return Response(400, body: "Missing code or redirect_uri");
|
||||||
|
}
|
||||||
|
|
||||||
|
final tokenRes = await tokenHandler(
|
||||||
|
Request(
|
||||||
|
"POST",
|
||||||
|
Uri.base,
|
||||||
|
body: json.encode({"code": code, "client_id": "proxy"}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final uri = Uri.parse(redirectUri).replace(
|
||||||
|
queryParameters: {
|
||||||
|
...Uri.parse(redirectUri).queryParameters,
|
||||||
|
...json.decode(await tokenRes.readAsString()),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return Response.found(uri.toString());
|
||||||
|
}
|
||||||
|
|
||||||
Future<Response> userinfoHandler(Request request) async {
|
Future<Response> userinfoHandler(Request request) async {
|
||||||
final auth = request.headers["authorization"];
|
final auth = request.headers["authorization"];
|
||||||
if (auth == null || !auth.startsWith("Bearer ")) {
|
if (auth == null || !auth.startsWith("Bearer ")) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue