Exemplo n.º 1
0
 /**
  * handle
  */
 public function handle()
 {
     $clientRepository = new ClientRepository();
     $scopeRepository = new ScopeRepository();
     $accessTokenRepository = new AccessTokenRepository();
     $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 RefreshTokenGrant($refreshTokenRepository);
     $grant->setRefreshTokenTTL(new \DateInterval($refreshTokenTTL));
     $server->enableGrantType($grant, new \DateInterval($accessTokenTTL));
     return $server;
 }
Exemplo n.º 2
0
    $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);
    $authCodeGrant->setRefreshTokenTTL($refreshTokenLifetime);
    $server->enableGrantType($authCodeGrant, $accessTokenLifetime);
    /**
     * Using response_type=token & client_id & redirect_uri & state
     */
    $server->enableGrantType(new ImplicitGrant($accessTokenLifetime), $accessTokenLifetime);
    return $server;
});
Exemplo n.º 3
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;
 }