function it_issues_access_token_using_grant_type_of_given_request(IRequest $request, IGrantTypeResolver $grantTypeResolver, IGrantType $grantType, IAccessToken $accessToken) { $request->isMethod('post')->willReturn(true)->shouldBeCalled(); $grantTypeResolver->resolve($request)->willReturn($grantType)->shouldBeCalled(); $grantType->grant($request)->willReturn($accessToken)->shouldBeCalled(); $this->issueToken($request)->shouldReturnAnInstanceOf('OAuth2\\Storage\\IAccessToken'); }
/** * Issues access token using grant type from current request * * @param IRequest $request * * @return \OAuth2\Storage\IAccessToken * @throws \OAuth2\Exception\InvalidHttpMethodException */ public function issueToken(IRequest $request) { if (!$request->isMethod('post')) { throw new InvalidHttpMethodException(); } $grantType = $this->grantTypeResolver->resolve($request); return $grantType->grant($request); }
/** * Authorizes request using grant type with authorization * * @param IRequest $request * @param IUser $user logged user * * @return IAuthorizationSession * @throws \OAuth2\Exception\UnsupportedResponseTypeException */ public function authorize(IRequest $request, IUser $user) { // resolve grant type for current request $grantType = $this->grantTypeResolver->resolve($request); if (!$grantType instanceof IAuthorizationGrantType) { throw new UnsupportedResponseTypeException(); } return $grantType->authorize($request, $user); }
function it_throws_exception_on_invalid_grant_type(IGrantTypeResolver $grantTypeResolver, IRequest $request, IGrantType $grantType, IUser $user) { $grantTypeResolver->resolve($request)->willReturn($grantType)->shouldBeCalled(); $this->shouldThrow('OAuth2\\Exception\\UnsupportedResponseTypeException')->during('authorize', [$request, $user]); }