private function registerOAuthServer()
  {
    $this->app->bind('League\OAuth2\Server\Storage\ClientInterface', 'Sule\Api\OAuth2\Repositories\FluentClient');
    $this->app->bind('League\OAuth2\Server\Storage\ScopeInterface', 'Sule\Api\OAuth2\Repositories\FluentScope');
    $this->app->bind('League\OAuth2\Server\Storage\SessionInterface', 'Sule\Api\OAuth2\Repositories\FluentSession');
    $this->app->bind('Sule\Api\OAuth2\Repositories\SessionManagementInterface', 'Sule\Api\OAuth2\Repositories\FluentSession');

    $this->app['api.authorization'] = $this->app->share(function ($app) {

      $server = $app->make('League\OAuth2\Server\Authorization');

      $config = $app['config']->get('sule/api::oauth2');

      // add the supported grant types to the authorization server
      foreach ($config['grant_types'] as $grantKey => $grantValue) {

        $server->addGrantType(new $grantValue['class']($server));
        $server->getGrantType($grantKey)->setAccessTokenTTL($grantValue['access_token_ttl']);

        if (array_key_exists('callback', $grantValue)) {
          $server->getGrantType($grantKey)->setVerifyCredentialsCallback($grantValue['callback']);
        }

        if (array_key_exists('auth_token_ttl', $grantValue)) {
          $server->getGrantType($grantKey)->setAuthTokenTTL($grantValue['auth_token_ttl']);
        }

        if (array_key_exists('refresh_token_ttl', $grantValue)) {
          $server->getGrantType($grantKey)->setRefreshTokenTTL($grantValue['refresh_token_ttl']);
        }

        if (array_key_exists('rotate_refresh_tokens', $grantValue)) {
          $server->getGrantType($grantKey)->rotateRefreshTokens($grantValue['rotate_refresh_tokens']);
        }
      }

      $server->requireStateParam($config['state_param']);

      $server->requireScopeParam($config['scope_param']);

      $server->setScopeDelimeter($config['scope_delimiter']);

      $server->setDefaultScope($config['default_scope']);

      $server->setAccessTokenTTL($config['access_token_ttl']);

      return new OAuthServer($server);

    });

    $this->app['api.resource'] = $this->app->share(function ($app) {

      return $app->make('Sule\Api\OAuth2\Resource');

    });
  }