From 0b72dc999dd6244ee06524fd8d357f93b19a699c Mon Sep 17 00:00:00 2001 From: Sebastian Marcet Date: Wed, 8 Aug 2018 15:56:55 -0300 Subject: [PATCH] Fix 400 error on auth code grant readded code to get user by user id on auth code if session cookie is missing Change-Id: I7e40b5165acc9388229f322e9822ef1b0502f00c --- app/Services/OAuth2/TokenService.php | 8 +++++++- app/libs/OAuth2/GrantTypes/AuthorizationCodeGrantType.php | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Services/OAuth2/TokenService.php b/app/Services/OAuth2/TokenService.php index 5ac3c849..9f3975da 100644 --- a/app/Services/OAuth2/TokenService.php +++ b/app/Services/OAuth2/TokenService.php @@ -1436,7 +1436,13 @@ final class TokenService implements ITokenService $user = $this->auth_service->getCurrentUser(); - if(!$user) + if(is_null($user)){ + $user_id = $this->principal_service->get()->getUserId(); + Log::debug(sprintf("user id is %s", $user_id)); + $user = $this->auth_service->getUserById($user_id); + } + + if(is_null($user)) throw new AbsentCurrentUserException; // build claim set diff --git a/app/libs/OAuth2/GrantTypes/AuthorizationCodeGrantType.php b/app/libs/OAuth2/GrantTypes/AuthorizationCodeGrantType.php index dc574df4..f2059443 100644 --- a/app/libs/OAuth2/GrantTypes/AuthorizationCodeGrantType.php +++ b/app/libs/OAuth2/GrantTypes/AuthorizationCodeGrantType.php @@ -250,6 +250,12 @@ class AuthorizationCodeGrantType extends InteractiveGrantType throw new UriNotAllowedException($current_redirect_uri); } + $this->principal_service->register + ( + $auth_code->getUserId(), + $auth_code->getAuthTime() + ); + $response = OAuth2AccessTokenResponseFactory::build ( $this->token_service,