Select key "push key" by default for new keys

This commit is contained in:
lemoer 2025-07-05 22:37:54 +02:00
parent 8ce3805f4e
commit 7c5251fb99

View File

@ -191,7 +191,7 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
onPressed: authentikApiState.start, onPressed: () => authentikApiState.start(key),
child: Text("Oauth2 Login"), child: Text("Oauth2 Login"),
), ),
Text('Current output:'), Text('Current output:'),
@ -294,13 +294,15 @@ class _MyHomePageState extends State<MyHomePage> {
case AuthentikUserSettingsChangeDialogStatus.userSettingsObtained: case AuthentikUserSettingsChangeDialogStatus.userSettingsObtained:
title = Text("User Settings Obtained"); title = Text("User Settings Obtained");
children = [Text("You can now edit your user settings.")]; children = [Text("You can now edit your user settings.")];
for (var k in authentikApiState.allKeys) {
children.add(KeepOrDeleteKey(sshKey: k, isOurKey: k == key));
}
if (!authentikApiState.allKeys.contains(key)) {
// If the key is not already in the list, add it
children.add(KeepOrDeleteKey(sshKey: key, isOurKey: true)); children.add(KeepOrDeleteKey(sshKey: key, isOurKey: true));
for (var k in authentikApiState.allKeys) {
if (k == key) {
// Skip our key, since the widget is on top already
continue;
}
children.add(KeepOrDeleteKey(sshKey: k));
} }
actions.add( actions.add(
@ -424,7 +426,7 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
return await grant.handleAuthorizationResponse(queryParameters); return await grant.handleAuthorizationResponse(queryParameters);
} }
Future<void> start() async { Future<void> start(String currentKey) async {
// Reset the state to be sure // Reset the state to be sure
oauthClient = null; oauthClient = null;
sessionCookie = null; sessionCookie = null;
@ -468,6 +470,12 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
.split('\n') .split('\n')
.where((key) => key.isNotEmpty) .where((key) => key.isNotEmpty)
.toList(); .toList();
_keysToKeep = _allKeys.toList();
if (!_keysToKeep.contains(currentKey)) {
// If the current key is not in the list of keys to keep, add it
_keysToKeep.add(currentKey);
}
} else { } else {
throw Exception( throw Exception(
"Expected 'attributes.sshPublicKeys' in user settings, but got: $userSettings", "Expected 'attributes.sshPublicKeys' in user settings, but got: $userSettings",