Some cleanup

This commit is contained in:
lemoer 2025-07-06 15:37:57 +02:00
parent 7a757248c7
commit 846ef5bf1c

View File

@ -387,7 +387,7 @@ class _MyHomePageState extends State<MyHomePage> {
return mainPage; return mainPage;
} }
var title; Widget title;
var children = <Widget>[]; var children = <Widget>[];
var actions = [ var actions = [
TextButton(onPressed: authentikApiState.exit, child: Text("Cancel")), TextButton(onPressed: authentikApiState.exit, child: Text("Cancel")),
@ -472,9 +472,6 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
List<String> get keysToKeep => _keysToKeep; List<String> get keysToKeep => _keysToKeep;
Future<oauth2.Client?> getOAuth2Client() async { Future<oauth2.Client?> getOAuth2Client() async {
// This is a placeholder for OAuth2 client initialization.
// Replace with your actual OAuth2 client setup.
final authorizationEndpoint = Uri.parse( final authorizationEndpoint = Uri.parse(
'https://auth.leinelab.org/application/o/authorize/', 'https://auth.leinelab.org/application/o/authorize/',
); );
@ -484,23 +481,10 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
); );
final identifier = 'UwSMm8gTwBTUURSaxp5uPpuwX1OkGO4FRHeO9v3i'; final identifier = 'UwSMm8gTwBTUURSaxp5uPpuwX1OkGO4FRHeO9v3i';
final secret = null; // = 'my client secret'; final secret = null;
final redirectUrl = Uri.parse('http://localhost:30165/'); 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( var grant = oauth2.AuthorizationCodeGrant(
identifier, identifier,
authorizationEndpoint, authorizationEndpoint,
@ -513,18 +497,19 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
scopes: ["profile", "email", "goauthentik.io/api", "openid"], 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); server = await HttpServer.bind("127.0.0.1", 30165);
await launchUrl(authorizationUrl); await launchUrl(authorizationUrl);
var queryParameters;
if (server == null) { if (server == null) {
// exit() might have been called before we arrived here. // exit() might have been called before we arrived here.
return null; return null;
} }
// When the http server receives a request, we store the query parameters,
// so the oauth2 client can handle the response.
Map<String, String>? queryParameters;
await server!.forEach((HttpRequest request) { await server!.forEach((HttpRequest request) {
request.response.write( request.response.write(
'Success! You can close this window now and go back to the app.', 'Success! You can close this window now and go back to the app.',
@ -534,7 +519,12 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
server!.close(); 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<void> start(String currentKey) async { Future<void> start(String currentKey) async {