From 846ef5bf1ce66f70a352ade42997eada24b46b51 Mon Sep 17 00:00:00 2001 From: lemoer Date: Sun, 6 Jul 2025 15:37:57 +0200 Subject: [PATCH] Some cleanup --- lib/main.dart | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index eaa750f..a6b972d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -387,7 +387,7 @@ class _MyHomePageState extends State { return mainPage; } - var title; + Widget title; var children = []; var actions = [ TextButton(onPressed: authentikApiState.exit, child: Text("Cancel")), @@ -472,9 +472,6 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier { List get keysToKeep => _keysToKeep; Future getOAuth2Client() async { - // This is a placeholder for OAuth2 client initialization. - // Replace with your actual OAuth2 client setup. - final authorizationEndpoint = Uri.parse( 'https://auth.leinelab.org/application/o/authorize/', ); @@ -484,23 +481,10 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier { ); final identifier = 'UwSMm8gTwBTUURSaxp5uPpuwX1OkGO4FRHeO9v3i'; - final secret = null; // = 'my client secret'; + final secret = null; final redirectUrl = Uri.parse('http://localhost:30165/'); - // final credentialsFile = File('~/.myapp/credentials.json'); - - // //.... - - // var exists = await credentialsFile.exists(); - - // if (exists) { - // var credentials = oauth2.Credentials.fromJson( - // await credentialsFile.readAsString(), - // ); - // return oauth2.Client(credentials, identifier: identifier, secret: secret); - // } - var grant = oauth2.AuthorizationCodeGrant( identifier, authorizationEndpoint, @@ -513,18 +497,19 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier { scopes: ["profile", "email", "goauthentik.io/api", "openid"], ); - // TODO: clicking the button twice might try to bind the server twice server = await HttpServer.bind("127.0.0.1", 30165); await launchUrl(authorizationUrl); - var queryParameters; - if (server == null) { // exit() might have been called before we arrived here. return null; } + // When the http server receives a request, we store the query parameters, + // so the oauth2 client can handle the response. + Map? queryParameters; + await server!.forEach((HttpRequest request) { request.response.write( 'Success! You can close this window now and go back to the app.', @@ -534,7 +519,12 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier { server!.close(); }); - return await grant.handleAuthorizationResponse(queryParameters); + if (queryParameters == null) { + // If we did not receive any query parameters, exit + return null; + } + + return await grant.handleAuthorizationResponse(queryParameters!); } Future start(String currentKey) async {