static function auth(ProviderInterface $provider) {
    if (!require_get("code", false)) {
      redirect($provider->getAuthorizationUrl());
      return false;
    } else {
      // optionally check for abuse etc
      if (!\Openclerk\Events::trigger('oauth2_auth', $provider)) {
        throw new UserAuthenticationException("Login was cancelled by the system.");
      }

      $token = $provider->getAccessToken('authorization_code', array(
        'code' => require_get("code"),
      ));

      // now find the relevant user
      return $provider->getUserDetails($token);
    }
  }