code: @Override
    public void onConnect(URI serverHost) throws IOException {
      if (!StringUtils.isEmpty(accessToken)) {
        return; //No need to be called if accessToken is active.
      }
  
      try {
        getLog().info("Getting Oauth2 access token.");
        OAuthClientRequest request = OAuthClientRequest.tokenLocation(serverHost.toString())
            .setGrantType(GrantType.PASSWORD)
            .setClientId(clientId)
            .setClientSecret(clientSecret)
            .setUsername(userId)
            .setPassword(password + securityToken).buildQueryMessage();
        OAuthClient client = new OAuthClient(new URLConnectionClient());
        OAuthJSONAccessTokenResponse response = client.accessToken(request, OAuth.HttpMethod.POST);
  
        accessToken = response.getAccessToken();
        setCurServerHost(new URI(response.getParam("instance_url")));
      } catch (OAuthProblemException e) {
        throw new NonTransientException("Error while authenticating with Oauth2", e);
      } catch (OAuthSystemException e) {
        throw new RuntimeException("Failed getting access token", e);
      } catch (URISyntaxException e) {
        throw new RuntimeException("Failed due to invalid instance url", e);
      }
    }
docs: Retrieve access token, if needed, retrieve instance url, and set server host URL
  {@inheritDoc}
  @see org.apache.gobblin.writer.http.HttpWriter#onConnect(org.apache.http.HttpHost)