Skip to content

Commit

Permalink
fix: handle null clientSecret gracefully (#47)
Browse files Browse the repository at this point in the history
This commit resolves issue #47 by updating the `casdoor.refreshToken` function to handle `null` values for `clientSecret`. When `clientSecret` is `null`, the field is now excluded from the request body, avoiding type casting errors.
  • Loading branch information
zHElEARN authored Jan 22, 2025
1 parent 3344394 commit 33d0408
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/src/casdoor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,23 @@ class Casdoor {

Future<http.Response> refreshToken(String refreshToken, String? clientSecret,
{String scope = 'read'}) async {
final body = {
'grant_type': 'refresh_token',
'refresh_token': refreshToken,
'scope': scope,
'client_id': config.clientId,
};
if (clientSecret != null) {
body['client_secret'] = clientSecret;
}
return await http.post(
Uri(
scheme: parseScheme(),
host: parseHost(),
port: parsePort(),
path: 'api/login/oauth/refresh_token',
),
body: {
'grant_type': 'refresh_token',
'refresh_token': refreshToken,
'scope': scope,
'client_id': config.clientId,
'client_secret': clientSecret
});
body: body);
}

Future<http.Response> tokenLogout(
Expand Down

0 comments on commit 33d0408

Please sign in to comment.