/**
  * Register the Authorization server with the IoC container
  * @return void
  */
 public function registerAuthorizer()
 {
     $this->app->bindShared('oauth2-server.authorizer', function ($app) {
         $config = $app['config']->get('oauth2');
         $limitClientsToGrants = $config['limit_clients_to_grants'];
         $limitClientsToScopes = $config['limit_clients_to_scopes'];
         // Authorization server
         $issuer = new AuthorizationServer();
         $issuer->setSessionStorage(new SessionStorage($app['db']));
         $issuer->setAccessTokenStorage(new AccessTokenStorage($app['db']));
         $issuer->setRefreshTokenStorage(new RefreshTokenStorage($app['db']));
         $issuer->setClientStorage(new ClientStorage($app['db'], $limitClientsToGrants));
         $issuer->setScopeStorage(new ScopeStorage($app['db'], $limitClientsToScopes, $limitClientsToGrants));
         $issuer->setAuthCodeStorage(new AuthCodeStorage($app['db']));
         $issuer->requireScopeParam($config['scope_param']);
         $issuer->setDefaultScope($config['default_scope']);
         $issuer->requireStateParam($config['state_param']);
         $issuer->setScopeDelimiter($config['scope_delimiter']);
         $issuer->setAccessTokenTTL($config['access_token_ttl']);
         // add the supported grant types to the authorization server
         foreach ($config['grant_types'] as $grantIdentifier => $grantParams) {
             $grant = new $grantParams['class']();
             $grant->setAccessTokenTTL($grantParams['access_token_ttl']);
             if (array_key_exists('callback', $grantParams)) {
                 $grant->setVerifyCredentialsCallback($grantParams['callback']);
             }
             if (array_key_exists('auth_token_ttl', $grantParams)) {
                 $grant->setAuthTokenTTL($grantParams['auth_token_ttl']);
             }
             if (array_key_exists('refresh_token_ttl', $grantParams)) {
                 $grant->setRefreshTokenTTL($grantParams['refresh_token_ttl']);
             }
             $issuer->addGrantType($grant);
         }
         // Resource server
         $sessionStorage = new SessionStorage($app['db']);
         $accessTokenStorage = new AccessTokenStorage($app['db']);
         $clientStorage = new ClientStorage($app['db'], $limitClientsToGrants);
         $scopeStorage = new ScopeStorage($app['db'], $limitClientsToScopes, $limitClientsToGrants);
         $checker = new ResourceServer($sessionStorage, $accessTokenStorage, $clientStorage, $scopeStorage);
         $authorizer = new Authorizer($issuer, $checker);
         $authorizer->setRequest($app['request']);
         $authorizer->setTokenType($app->make($config['token_type']));
         $app->refresh('request', $authorizer, 'setRequest');
         return $authorizer;
     });
     $this->app->bind('Rapiro\\OAuth2Server\\Authorizer', function ($app) {
         return $app['oauth2-server.authorizer'];
     });
 }
 /**
  * Configures the authorization server instance.
  *
  * @param AuthorizationServer $authorizationServer
  * @param array               $config
  */
 protected function configureAuthorizationServer(AuthorizationServer $authorizationServer, array $config)
 {
     if (isset($config['scope_param'])) {
         $authorizationServer->requireScopeParam($config['scope_param']);
     }
     if (isset($config['default_scope'])) {
         $authorizationServer->setDefaultScope($config['default_scope']);
     }
     if (isset($config['state_param'])) {
         $authorizationServer->requireStateParam($config['state_param']);
     }
     if (isset($config['scope_delimiter'])) {
         $authorizationServer->setScopeDelimiter($config['scope_delimiter']);
     }
     if (isset($config['access_token_ttl'])) {
         $authorizationServer->setAccessTokenTTL($config['access_token_ttl']);
     }
     $this->configureGrantTypes($authorizationServer, $config['grant_types']);
 }