From 582227bc957edb38413a3873637577e602432b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20B=C3=B6cker?= Date: Fri, 4 Sep 2020 15:14:59 +0200 Subject: [PATCH 1/2] Support id_token responses in JwtFlow --- lib/src/oauth2_flows/jwt.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/src/oauth2_flows/jwt.dart b/lib/src/oauth2_flows/jwt.dart index 0aaaf54..aa1931b 100644 --- a/lib/src/oauth2_flows/jwt.dart +++ b/lib/src/oauth2_flows/jwt.dart @@ -75,11 +75,20 @@ class JwtFlow { .transform(json.decoder) .first; Map response = object as Map; - var tokenType = response['token_type']; - var token = response['access_token']; - var expiresIn = response['expires_in']; + String tokenType = response['token_type']; + String token = response['access_token']; + int expiresIn = response['expires_in']; var error = response['error']; + if (response['id_token'] != null) { + tokenType = 'Bearer'; + token = response['id_token']; + final payloadB64 = token.split('.')[1]; + final decoded = + jsonDecode(ascii.decode(base64Decode(base64.normalize(payloadB64)))); + expiresIn = decoded['exp'] * 1000; + } + if (httpResponse.statusCode != 200 && error != null) { throw new Exception('Unable to obtain credentials. Error: $error.'); } From c004a31205955a7c9e50e8f21bdaa6395e6d9227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20B=C3=B6cker?= Date: Fri, 4 Sep 2020 15:36:38 +0200 Subject: [PATCH 2/2] format with newer Dart version --- lib/src/oauth2_flows/implicit.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/oauth2_flows/implicit.dart b/lib/src/oauth2_flows/implicit.dart index 66d5113..a90dae6 100644 --- a/lib/src/oauth2_flows/implicit.dart +++ b/lib/src/oauth2_flows/implicit.dart @@ -141,7 +141,9 @@ class ImplicitFlow { ? responseTypes .map((responseType) => _responseTypeToString(responseType)) .join(' ') - : hybrid ? 'code token' : 'token', + : hybrid + ? 'code token' + : 'token', 'scope': _scopes.join(' '), 'access_type': hybrid ? 'offline' : 'online', };