Beispiel #1
0
 public function delete($userId, $grantId)
 {
     $grant = $this->userGrantTable->get($grantId);
     if (!empty($grant)) {
         if ($grant['userId'] == $userId) {
             try {
                 $this->userGrantTable->beginTransaction();
                 $this->userGrantTable->delete($grant);
                 // delete tokens
                 $this->appTokenTable->removeAllTokensFromAppAndUser($grant['appId'], $grant['userId']);
                 $this->userGrantTable->commit();
             } catch (\Exception $e) {
                 $this->userGrantTable->rollBack();
                 throw $e;
             }
         } else {
             throw new StatusCode\BadRequestException('Invalid grant id');
         }
     } else {
         throw new StatusCode\NotFoundException('Could not find grant');
     }
 }
Beispiel #2
0
 public function generateAccessToken($appId, $userId, array $scopes, $ip, DateInterval $expire)
 {
     if (empty($scopes)) {
         throw new StatusCode\BadRequestException('No scopes provided');
     }
     $expires = new \DateTime();
     $expires->add($expire);
     $now = new \DateTime();
     // generate access token
     $accessToken = TokenGenerator::generateToken();
     $this->appTokenTable->create(['appId' => $appId, 'userId' => $userId, 'status' => Table\App\Token::STATUS_ACTIVE, 'token' => $accessToken, 'scope' => implode(',', $scopes), 'ip' => $ip, 'expire' => $expires, 'date' => $now]);
     $token = new AccessToken();
     $token->setAccessToken($accessToken);
     $token->setTokenType('bearer');
     $token->setExpiresIn($expires->getTimestamp());
     $token->setScope(implode(',', $scopes));
     return $token;
 }