コード例 #1
0
 function it_authenticates_request_and_throws_exception_if_access_token_does_not_exist(IRequest $request, ITokenTypeResolver $tokenTypeResolver, ITokenType $tokenType, IAccessTokenStorage $accessTokenStorage)
 {
     $tokenTypeResolver->resolve($request)->willReturn($tokenType)->shouldBeCalled();
     $tokenType->getAccessToken()->willReturn('abcd')->shouldBeCalled();
     $accessTokenStorage->get('abcd')->willReturn(null)->shouldBeCalled();
     $this->shouldThrow('OAuth2\\Exception\\NotAuthenticatedException')->during('authenticate', [$request]);
 }
コード例 #2
0
 /**
  * Authenticates current request and returns session
  *
  * @param IRequest $request
  *
  * @throws \OAuth2\Exception\NotAuthenticatedException
  * @return Session
  */
 public function authenticate(IRequest $request)
 {
     // resolve token type from request
     $tokenType = $this->tokenTypeResolver->resolve($request);
     $accessToken = $this->accessTokenStorage->get($tokenType->getAccessToken());
     if (!$accessToken) {
         throw new NotAuthenticatedException();
     }
     return new Session($accessToken);
 }