public function callbackAction()
 {
     $provider = $this->getProvider();
     $provider->authenticate();
     $profile = $provider->getUserProfile();
     $providerName = strtolower($this->getRequest()->getQuery('provider'));
     /** @var User $user */
     $user = $this->entityManager->getRepository(\Application\Model\User::class)->createOrUpdate($providerName, $profile);
     $this->entityManager->flush();
     $jwt = new \OAuth2\Encryption\Jwt();
     $filename = null;
     if ($user->getImage()) {
         $filename = (new ImageHydrator())->extract($user->getImage()->getFilename());
     }
     $message = ['id' => $user->getId(), 'name' => $user->getName(), 'photo' => $user->getPhoto(), 'image' => $filename, 'language' => $user->getLanguage()];
     $token = $jwt->encode($message, $this->cryptoKey);
     $uri = $this->getRequest()->getUri();
     $base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
     return $this->redirect()->toUrl($base . '/receive.html?token=' . $token);
 }
示例#2
0
 /**
  * Generate a JWT
  *
  * @param   string  $privateKey  The private key to use to sign the token
  * @param   string  $iss         The issuer, usually the client_id
  * @param   string  $sub         The subject, usually a user_id
  * @param   string  $aud         The audience, usually the URI for the oauth server
  * @param   string  $exp         The expiration date. If the current time is greater than the exp, the JWT is invalid
  * @param   string  $nbf         The "not before" time. If the current time is less than the nbf, the JWT is invalid
  * @param   string  $jti         The "jwt token identifier", or nonce for this JWT
  *
  * @return string  JWT
  */
 public static function generateJWT($privateKey, $iss, $sub, $aud, $exp = null, $nbf = null, $jti = null)
 {
     if (!$exp) {
         $exp = time() + 1000;
     }
     $params = array('iss' => $iss, 'sub' => $sub, 'aud' => $aud, 'exp' => $exp, 'iat' => time());
     if ($nbf) {
         $params['nbf'] = $nbf;
     }
     if ($jti) {
         $params['jti'] = $jti;
     }
     $jwtUtil = new \OAuth2\Encryption\Jwt();
     return $jwtUtil->encode($params, $privateKey, 'RS256');
 }