From 728cc52d9c5d28189647c434fb4596c5ea0b6d7b Mon Sep 17 00:00:00 2001 From: Udhay-Adithya Date: Wed, 23 Jul 2025 12:48:10 +0530 Subject: [PATCH] fix: improve oauth2 field --- .../common_widgets/auth/oauth2_field.dart | 16 +++++++--------- .../lib/utils/auth/handle_auth.dart | 4 +++- .../lib/utils/auth/oauth2_utils.dart | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/screens/common_widgets/auth/oauth2_field.dart b/lib/screens/common_widgets/auth/oauth2_field.dart index d7fe4340..4d13ccf4 100644 --- a/lib/screens/common_widgets/auth/oauth2_field.dart +++ b/lib/screens/common_widgets/auth/oauth2_field.dart @@ -55,11 +55,11 @@ class _OAuth2FieldsState extends State { _usernameController = TextEditingController(text: oauth2?.username ?? ''); _passwordController = TextEditingController(text: oauth2?.password ?? ''); _refreshTokenController = - TextEditingController(text: oauth2?.refreshToken ?? 'N/A'); + TextEditingController(text: oauth2?.refreshToken ?? ''); _identityTokenController = - TextEditingController(text: oauth2?.identityToken ?? 'N/A'); + TextEditingController(text: oauth2?.identityToken ?? ''); _accessTokenController = - TextEditingController(text: oauth2?.accessToken ?? 'N/A'); + TextEditingController(text: oauth2?.accessToken ?? ''); _codeChallengeMethod = oauth2?.codeChallengeMethod ?? 'sha-256'; // Load credentials from file if available @@ -79,8 +79,8 @@ class _OAuth2FieldsState extends State { } else { _refreshTokenController.text = "N/A"; } - if (decoded['id_token'] != null) { - _identityTokenController.text = decoded['identityToken']!; + if (decoded['idToken'] != null) { + _identityTokenController.text = decoded['idToken']!; } else { _identityTokenController.text = "N/A"; } @@ -89,6 +89,7 @@ class _OAuth2FieldsState extends State { } else { _accessTokenController.text = "N/A"; } + // "expiration": 1753258479104 }); } } @@ -98,7 +99,7 @@ class _OAuth2FieldsState extends State { Widget build(BuildContext context) { return ListView( shrinkWrap: true, - physics: AlwaysScrollableScrollPhysics(), + physics: ClampingScrollPhysics(), children: [ Text( "Grant Type", @@ -243,7 +244,6 @@ class _OAuth2FieldsState extends State { readOnly: widget.readOnly, controller: _refreshTokenController, hintText: "Refresh Token", - isObscureText: true, onChanged: (_) => _updateOAuth2(), ), ), @@ -252,7 +252,6 @@ class _OAuth2FieldsState extends State { readOnly: widget.readOnly, controller: _identityTokenController, hintText: "Identity Token", - isObscureText: true, onChanged: (_) => _updateOAuth2(), ), ), @@ -260,7 +259,6 @@ class _OAuth2FieldsState extends State { AuthTextField( readOnly: widget.readOnly, controller: _accessTokenController, - isObscureText: true, hintText: "Access Token", onChanged: (_) => _updateOAuth2(), ), diff --git a/packages/better_networking/lib/utils/auth/handle_auth.dart b/packages/better_networking/lib/utils/auth/handle_auth.dart index ca781fe2..63cc802e 100644 --- a/packages/better_networking/lib/utils/auth/handle_auth.dart +++ b/packages/better_networking/lib/utils/auth/handle_auth.dart @@ -197,7 +197,9 @@ Future handleAuth( secret: oauth2.clientSecret, authorizationEndpoint: Uri.parse(oauth2.authorizationUrl), redirectUrl: Uri.parse( - oauth2.redirectUrl ?? "apidash://oauth2/callback", + oauth2.redirectUrl!.isEmpty + ? "apidash://oauth2/callback" + : oauth2.redirectUrl!, ), tokenEndpoint: Uri.parse(oauth2.accessTokenUrl), credentialsFile: credentialsFile, diff --git a/packages/better_networking/lib/utils/auth/oauth2_utils.dart b/packages/better_networking/lib/utils/auth/oauth2_utils.dart index 9a080cdc..2582e0d8 100644 --- a/packages/better_networking/lib/utils/auth/oauth2_utils.dart +++ b/packages/better_networking/lib/utils/auth/oauth2_utils.dart @@ -65,6 +65,7 @@ Future oAuth2AuthorizationCodeGrantHandler({ log('OAuth2 authorization successful, saving credentials'); await credentialsFile.writeAsString(client.credentials.toJson()); + log(client.credentials.toJson()); return client; } catch (e) {