Exemplo n.º 1
0
 /**
  * enable RefreshTokenGrant.
  *
  * @param $options
  *
  * @return RefreshTokenGrant
  */
 public function enableRefreshTokenGrant($options)
 {
     // Init our repositories
     $refreshTokenRepository = new RefreshTokenRepository();
     $grant = new RefreshTokenGrant($refreshTokenRepository);
     $grant->setRefreshTokenTTL($this->getDateInterval($options['refresh_token_ttl']));
     // Enable the refresh token grant on the server
     $this->authorizationServer->enableGrantType($grant, $this->getDateInterval($options['access_token_ttl']));
     return $grant;
 }
Exemplo n.º 2
0
 /**
  * handle
  */
 public function handle()
 {
     $clientRepository = new ClientRepository();
     $scopeRepository = new ScopeRepository();
     $accessTokenRepository = new AccessTokenRepository();
     $config = Yii::$container->get(ConfigInterface::class);
     $privateKey = $config->get('privateKeyPath');
     $publicKey = $config->get('publicKeyPath');
     $server = new AuthorizationServer($clientRepository, $accessTokenRepository, $scopeRepository, $privateKey, $publicKey);
     $accessTokenTTL = $config->get('accessTokenTTL', 'PT1H');
     $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval($accessTokenTTL));
     return $server;
 }
Exemplo n.º 3
0
 /**
  * handle
  */
 public function handle()
 {
     $clientRepository = new ClientRepository();
     $scopeRepository = new ScopeRepository();
     $accessTokenRepository = new AccessTokenRepository();
     $userRepository = new UserRepository();
     $refreshTokenRepository = new RefreshTokenRepository();
     $config = Yii::$container->get(ConfigInterface::class);
     $privateKey = $config->get('privateKeyPath');
     $publicKey = $config->get('publicKeyPath');
     $server = new AuthorizationServer($clientRepository, $accessTokenRepository, $scopeRepository, $privateKey, $publicKey);
     $refreshTokenTTL = $config->get('refreshTokenTTL', 'P1M');
     $accessTokenTTL = $config->get('accessTokenTTL', 'PT1H');
     $grant = new PasswordGrant($userRepository, $refreshTokenRepository);
     $grant->setRefreshTokenTTL(new \DateInterval($refreshTokenTTL));
     $server->enableGrantType($grant, new \DateInterval($accessTokenTTL));
     return $server;
 }
Exemplo n.º 4
0
$di->setShared('authorizationServer', function () use($di) {
    $config = $di->getShared('config');
    $server = new AuthorizationServer(new ClientRepository(), new AccessTokenRepository(), new ScopeRepository(), 'file://' . __DIR__ . '/' . $config->oauth['private'], 'file://' . __DIR__ . '/' . $config->oauth['public']);
    $userRepository = new UserRepository();
    $refreshTokenRepository = new RefreshTokenRepository();
    $authCodeRepository = new AuthCodeRepository();
    $accessTokenLifetime = new \DateInterval($config->oauth['accessTokenLifetime']);
    $refreshTokenLifetime = new \DateInterval($config->oauth['refreshTokenLifetime']);
    $authorizationCodeLifetime = new \DateInterval($config->oauth['authorizationCodeLifetime']);
    /**
     * Using client_id & client_secret & username & password
     *
     */
    $passwordGrant = new PasswordGrant($userRepository, $refreshTokenRepository);
    $passwordGrant->setRefreshTokenTTL($refreshTokenLifetime);
    $server->enableGrantType($passwordGrant, $accessTokenLifetime);
    /**
     * Using client_id & client_secret
     */
    $clientCredentialsGrant = new ClientCredentialsGrant();
    $server->enableGrantType($clientCredentialsGrant, $accessTokenLifetime);
    /**
     * Using client_id & client_secret
     */
    $refreshTokenGrant = new RefreshTokenGrant($refreshTokenRepository);
    $refreshTokenGrant->setRefreshTokenTTL($refreshTokenLifetime);
    $server->enableGrantType($refreshTokenGrant, $accessTokenLifetime);
    /**
     * Using response_type=code & client_id & redirect_uri & state
     */
    $authCodeGrant = new AuthCodeGrant($authCodeRepository, $refreshTokenRepository, $authorizationCodeLifetime);