/** * Authorizes request * * @param IRequest $request * @param IUser $user logged user * * @throws \OAuth2\Exception\InvalidClientException * @throws \OAuth2\Exception\InvalidRequestException * @throws \OAuth2\Exception\InvalidScopeException * @throws \OAuth2\Exception\UnauthorizedClientException * @return AuthorizationCodeSession */ public function authorize(IRequest $request, IUser $user) { $requirements = parent::parseAuthorizationRequest($request, $user); // redirect uri is without authorization code! $authorizationCode = $this->authorizationCodeStorage->generate($user, $requirements['client'], $requirements['scopes'], $requirements['redirect_uri'], $requirements['state']); return new AuthorizationCodeSession($authorizationCode); }
function it_issues_authorization_code_and_creates_authorization_session(IRequest $request, IClientStorage $clientStorage, IClient $client, IAuthorizationCodeStorage $authorizationCodeStorage, IAuthorizationCode $authorizationCode, IScopeResolver $scopeResolver, IScope $scope, IUser $user) { $request->query('client_id')->willReturn('a')->shouldBeCalled(); $request->query('redirect_uri')->willReturn(null)->shouldBeCalled(); $clientStorage->get('a')->willReturn($client)->shouldBeCalled(); $client->isAllowedToUse($this)->willReturn(true)->shouldBeCalled(); $client->getRedirectUri()->willReturn('http://google.sk')->shouldBeCalled(); $request->query('state')->willReturn('test')->shouldBeCalled(); $request->query('scope')->willReturn(null)->shouldBeCalled(); $user->getScopes()->willReturn([$scope])->shouldBeCalled(); $scopeResolver->intersect(null, [$scope])->willReturn([$scope])->shouldBeCalled(); $authorizationCodeStorage->generate($user, $client, [$scope], 'http://google.sk', 'test')->willReturn($authorizationCode)->shouldBeCalled(); $this->authorize($request, $user)->shouldReturnAnInstanceOf('OAuth2\\Security\\AuthorizationCodeSession'); }