Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Support id_token responses in JwtFlow #81

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/src/oauth2_flows/implicit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
15 changes: 12 additions & 3 deletions lib/src/oauth2_flows/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down