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;
}
var title;
Widget title;
var children = <Widget>[];
var actions = [
TextButton(onPressed: authentikApiState.exit, child: Text("Cancel")),
@ -472,9 +472,6 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
List<String> get keysToKeep => _keysToKeep;
Future<oauth2.Client?> 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<String, String>? 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<void> start(String currentKey) async {