Hi everyone, I’ve built a custom Python connector ...
# help-connector-development
o
Hi everyone, I’ve built a custom Python connector for GitLab. GitLab’s OAuth system uses a single-use refresh token, which means that after each authentication, the refresh token becomes invalid and must be replaced with a new one from the response. Here’s an example of the response:
Copy code
{
  "access_token": "c97d1fe52119f38c7f67f0a14db68d60caa35ddc86fd12401718b649dcfa9c68",
  "token_type": "bearer",
  "expires_in": 7200,
  "refresh_token": "803c1fd487fec35562c205dac93e9d8e08f9d3652a24079d704df3039df1158f",
  "created_at": 1628711391
}
To re-authenticate, I need to use the new refresh token from the response. I’m using the
SingleUseRefreshTokenOauth2Authenticator
to handle this, which saves the new
refresh_token
,
access_token
, and
expire_time
in memory for the next authentication. The issue is that while these config values are correctly saved and used in memory, they are not being persisted in storage for future runs. When I create a new source, a validation check is performed, which passes and creates the source. However, after this check, the OAuth refresh token becomes invalid, and the new one isn’t saved to storage. As a result, I can’t create a new connection based on this source since the refresh token isn’t being updated in storage. Is anyone faced this issue before and knows how to solve it?
✅ 1
I found the solution to the issue. Here's what I changed: Before:
Copy code
return SingleUseRefreshTokenOauth2Authenticator(
    connector_config=config,
    token_refresh_endpoint=_TOKEN_REFRESH_ENDPOINT,
    client_id=gitlab_credentials["client_id"],
    client_secret=gitlab_credentials["client_secret"],
    access_token_config_path=("access_token"),
    refresh_token_config_path=("refresh_token"),
    token_expiry_date_config_path=("token_expiry_date"),
    refresh_request_body={
        "access_type": "offline",
    },
)
After:
Copy code
return SingleUseRefreshTokenOauth2Authenticator(
    connector_config=config,
    token_refresh_endpoint=_TOKEN_REFRESH_ENDPOINT,
    client_id=gitlab_credentials["client_id"],
    client_secret=gitlab_credentials["client_secret"],
    access_token_config_path=("access_token",),
    refresh_token_config_path=("refresh_token",),
    token_expiry_date_config_path=("token_expiry_date",),
    refresh_request_body={
        "access_type": "offline",
    },
)
The issue was that I was passing the paths as strings rather than tuples. In Python, when you place a value inside brackets (e.g.,
("access_token")
), it treats it as just that value, not as a tuple. This always bugs me when working with tuples that have only one value, because to make it a tuple, you need to add a comma:
Copy code
("access_token") -> ("access_token",)
a
@Ofek Eliahu did you need ROPC too?
o
@Aidan Lister in general ya, but I have my own
@Aidan Lister hi if noticed that i still have some issues with this for some reason when i create new source the values isn't being saved. but after the source has been created and i provide a new refresh token it does save the values but only the expiry time and the access token. i have no idea what is going on with this