diff --git a/lib/src/pkce.dart b/lib/src/pkce.dart index f2c710f7..35bae15a 100644 --- a/lib/src/pkce.dart +++ b/lib/src/pkce.dart @@ -64,4 +64,12 @@ class Pkce { ); } } + + /// Creates a JSON-serializable representation of this instance. + Map toJson() { + return { + 'code_challenge': codeChallenge, + 'code_challenge_method': codeChallengeMethod + }; + } } diff --git a/lib/src/server.dart b/lib/src/server.dart index 712c74c7..c8aa690e 100644 --- a/lib/src/server.dart +++ b/lib/src/server.dart @@ -215,6 +215,10 @@ abstract class AuthorizationServer { state = query['state']?.toString() ?? ''; var responseType = await _getParam(req, 'response_type', state); + req.container.registerLazySingleton((_) { + return new Pkce.fromJson(req.queryParameters, state: state); + }); + if (responseType == 'code') { // Ensure client ID // TODO: Handle confidential clients @@ -339,6 +343,10 @@ abstract class AuthorizationServer { state = body['state']?.toString() ?? ''; + req.container.registerLazySingleton((_) { + return new Pkce.fromJson(req.bodyAsMap, state: state); + }); + var grantType = await _getParam(req, 'grant_type', state, body: true, throwIfEmpty: false);