Merge branch 'patch-1'
diff --git a/lib/src/handle_access_token_response.dart b/lib/src/handle_access_token_response.dart
index 370ffcb..4c92810 100644
--- a/lib/src/handle_access_token_response.dart
+++ b/lib/src/handle_access_token_response.dart
@@ -68,9 +68,18 @@
}
var expiresIn = parameters['expires_in'];
- if (expiresIn != null && expiresIn is! int) {
- throw FormatException(
- 'parameter "expires_in" was not an int, was "$expiresIn"');
+ if (expiresIn != null) {
+ if (expiresIn is String) {
+ try {
+ expiresIn = double.parse(expiresIn).toInt();
+ } on FormatException {
+ throw FormatException(
+ 'parameter "expires_in" could not be parsed as in, was: "$expiresIn"');
+ }
+ } else if (expiresIn is! int) {
+ throw FormatException(
+ 'parameter "expires_in" was not an int, was: "$expiresIn"');
+ }
}
for (var name in ['refresh_token', 'id_token', 'scope']) {
diff --git a/test/handle_access_token_response_test.dart b/test/handle_access_token_response_test.dart
index 4561749..1663d3f 100644
--- a/test/handle_access_token_response_test.dart
+++ b/test/handle_access_token_response_test.dart
@@ -225,6 +225,12 @@
startTime.millisecondsSinceEpoch + 90 * 1000);
});
+ test('with expires-in encoded as string', () {
+ var credentials = handleSuccess(expiresIn: '110');
+ expect(credentials.expiration?.millisecondsSinceEpoch,
+ startTime.millisecondsSinceEpoch + 100 * 1000);
+ });
+
test('with a non-string refresh token throws a FormatException', () {
expect(() => handleSuccess(refreshToken: 12), throwsFormatException);
});