Ejemplo n.º 1
0
 /**
  * @param Request $request
  * @param string  $providerKey
  *
  * @return PreAuthenticatedToken
  */
 public function createToken(Request $request, $providerKey)
 {
     $tokenString = $request->headers->get('Authorization');
     if (0 === strpos($tokenString, 'Bearer ')) {
         $tokenString = substr($tokenString, 7);
     }
     if (!$tokenString) {
         throw new BadCredentialsException('No API key found');
     }
     try {
         $token = new JwtToken($tokenString);
         $key = $this->getKeyById($token->getKeyId());
         $key->validateToken($token);
     } catch (\Exception $e) {
         throw new AuthenticationException('Invalid key', 0, $e);
     }
     return new PreAuthenticatedToken('anon.', $token, $providerKey);
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function canGetKidWhenPresent()
 {
     $token = new JwtToken(self::KID_TOKEN);
     $this->assertSame('keyOne', $token->getKeyId());
 }