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 ?? '');
_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<OAuth2Fields> {
} 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<OAuth2Fields> {
} else {
_accessTokenController.text = "N/A";
}
// "expiration": 1753258479104
});
}
}
@@ -98,7 +99,7 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
Widget build(BuildContext context) {
return ListView(
shrinkWrap: true,
physics: AlwaysScrollableScrollPhysics(),
physics: ClampingScrollPhysics(),
children: [
Text(
"Grant Type",
@@ -243,7 +244,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
readOnly: widget.readOnly,
controller: _refreshTokenController,
hintText: "Refresh Token",
isObscureText: true,
onChanged: (_) => _updateOAuth2(),
),
),
@@ -252,7 +252,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
readOnly: widget.readOnly,
controller: _identityTokenController,
hintText: "Identity Token",
isObscureText: true,
onChanged: (_) => _updateOAuth2(),
),
),
@@ -260,7 +259,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
AuthTextField(
readOnly: widget.readOnly,
controller: _accessTokenController,
isObscureText: true,
hintText: "Access Token",
onChanged: (_) => _updateOAuth2(),
),

View File

@@ -197,7 +197,9 @@ Future<HttpRequestModel> 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,

View File

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