fix: improve oauth2 field

This commit is contained in:
Udhay-Adithya
2025-07-23 12:48:10 +05:30
parent 0c87374602
commit 728cc52d9c
3 changed files with 11 additions and 10 deletions

View File

@@ -55,11 +55,11 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
_usernameController = TextEditingController(text: oauth2?.username ?? ''); _usernameController = TextEditingController(text: oauth2?.username ?? '');
_passwordController = TextEditingController(text: oauth2?.password ?? ''); _passwordController = TextEditingController(text: oauth2?.password ?? '');
_refreshTokenController = _refreshTokenController =
TextEditingController(text: oauth2?.refreshToken ?? 'N/A'); TextEditingController(text: oauth2?.refreshToken ?? '');
_identityTokenController = _identityTokenController =
TextEditingController(text: oauth2?.identityToken ?? 'N/A'); TextEditingController(text: oauth2?.identityToken ?? '');
_accessTokenController = _accessTokenController =
TextEditingController(text: oauth2?.accessToken ?? 'N/A'); TextEditingController(text: oauth2?.accessToken ?? '');
_codeChallengeMethod = oauth2?.codeChallengeMethod ?? 'sha-256'; _codeChallengeMethod = oauth2?.codeChallengeMethod ?? 'sha-256';
// Load credentials from file if available // Load credentials from file if available
@@ -79,8 +79,8 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
} else { } else {
_refreshTokenController.text = "N/A"; _refreshTokenController.text = "N/A";
} }
if (decoded['id_token'] != null) { if (decoded['idToken'] != null) {
_identityTokenController.text = decoded['identityToken']!; _identityTokenController.text = decoded['idToken']!;
} else { } else {
_identityTokenController.text = "N/A"; _identityTokenController.text = "N/A";
} }
@@ -89,6 +89,7 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
} else { } else {
_accessTokenController.text = "N/A"; _accessTokenController.text = "N/A";
} }
// "expiration": 1753258479104
}); });
} }
} }
@@ -98,7 +99,7 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListView( return ListView(
shrinkWrap: true, shrinkWrap: true,
physics: AlwaysScrollableScrollPhysics(), physics: ClampingScrollPhysics(),
children: [ children: [
Text( Text(
"Grant Type", "Grant Type",
@@ -243,7 +244,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _refreshTokenController, controller: _refreshTokenController,
hintText: "Refresh Token", hintText: "Refresh Token",
isObscureText: true,
onChanged: (_) => _updateOAuth2(), onChanged: (_) => _updateOAuth2(),
), ),
), ),
@@ -252,7 +252,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _identityTokenController, controller: _identityTokenController,
hintText: "Identity Token", hintText: "Identity Token",
isObscureText: true,
onChanged: (_) => _updateOAuth2(), onChanged: (_) => _updateOAuth2(),
), ),
), ),
@@ -260,7 +259,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
AuthTextField( AuthTextField(
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _accessTokenController, controller: _accessTokenController,
isObscureText: true,
hintText: "Access Token", hintText: "Access Token",
onChanged: (_) => _updateOAuth2(), onChanged: (_) => _updateOAuth2(),
), ),

View File

@@ -197,7 +197,9 @@ Future<HttpRequestModel> handleAuth(
secret: oauth2.clientSecret, secret: oauth2.clientSecret,
authorizationEndpoint: Uri.parse(oauth2.authorizationUrl), authorizationEndpoint: Uri.parse(oauth2.authorizationUrl),
redirectUrl: Uri.parse( redirectUrl: Uri.parse(
oauth2.redirectUrl ?? "apidash://oauth2/callback", oauth2.redirectUrl!.isEmpty
? "apidash://oauth2/callback"
: oauth2.redirectUrl!,
), ),
tokenEndpoint: Uri.parse(oauth2.accessTokenUrl), tokenEndpoint: Uri.parse(oauth2.accessTokenUrl),
credentialsFile: credentialsFile, credentialsFile: credentialsFile,

View File

@@ -65,6 +65,7 @@ Future<oauth2.Client> oAuth2AuthorizationCodeGrantHandler({
log('OAuth2 authorization successful, saving credentials'); log('OAuth2 authorization successful, saving credentials');
await credentialsFile.writeAsString(client.credentials.toJson()); await credentialsFile.writeAsString(client.credentials.toJson());
log(client.credentials.toJson());
return client; return client;
} catch (e) { } catch (e) {