Compare commits

..

No commits in common. "09f68e7a6ef5b97d5b975532ac79135f3fabf1f3" and "7a757248c7488be13b631b5a0b4a491a4b337fe8" have entirely different histories.

View File

@ -101,6 +101,7 @@ class _MyHomePageState extends State<MyHomePage> {
); );
final uptime = await client.run('uptime'); final uptime = await client.run('uptime');
print(uptime);
setState(() { setState(() {
_output = utf8.decode(uptime); _output = utf8.decode(uptime);
}); });
@ -386,7 +387,7 @@ class _MyHomePageState extends State<MyHomePage> {
return mainPage; return mainPage;
} }
Widget title; var 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")),
@ -471,6 +472,9 @@ 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/',
); );
@ -480,10 +484,23 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
); );
final identifier = 'UwSMm8gTwBTUURSaxp5uPpuwX1OkGO4FRHeO9v3i'; final identifier = 'UwSMm8gTwBTUURSaxp5uPpuwX1OkGO4FRHeO9v3i';
final secret = null; final secret = null; // = 'my client secret';
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,
@ -496,19 +513,18 @@ 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.',
@ -518,12 +534,7 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier {
server!.close(); server!.close();
}); });
if (queryParameters == null) { return await grant.handleAuthorizationResponse(queryParameters);
// 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 {
@ -671,13 +682,13 @@ class KeepOrDeleteKey extends StatelessWidget {
); );
final buttonStyleKeepActive = ButtonStyle( final buttonStyleKeepActive = ButtonStyle(
backgroundColor: WidgetStateProperty.all(Colors.blue), backgroundColor: MaterialStateProperty.all(Colors.blue),
foregroundColor: WidgetStateProperty.all(Colors.white), foregroundColor: MaterialStateProperty.all(Colors.white),
); );
final buttonStyleDeleteActive = ButtonStyle( final buttonStyleDeleteActive = ButtonStyle(
backgroundColor: WidgetStateProperty.all(Colors.red), backgroundColor: MaterialStateProperty.all(Colors.red),
foregroundColor: WidgetStateProperty.all(Colors.white), foregroundColor: MaterialStateProperty.all(Colors.white),
); );
ButtonStyle? buttonStyleKeep; ButtonStyle? buttonStyleKeep;