Refresh gitlab tokens
We are now required to refresh the gitlab oauth tokens once they are expired.
- Implement a
refresh_token
method on the gitlab provider which makes the request described in step 3 there
redirect = 'https://arkindex.teklia.com' + reverse('api:oauth-callback', kwargs={'provider': 'gitlab'})
>>> parameters = {"client_id": settings.GITLAB_APP_ID, "client_secret": settings.GITLAB_APP_SECRET, "refresh_token": c.refresh_token, "grant_type": "refresh_token", "redirect_uri": redirect}
>>> out = requests.post('https://gitlab.com/oauth/token', parameters)
>>> out.json()
{'access_token': 'xxxxxxxxxxxxxx', 'token_type': 'Bearer', 'expires_in': 7200, 'refresh_token': 'yyyyyyyyyyyy', 'scope': 'api', 'created_at': 1652780416}
- when you get a successful payload, update immediately the
OauthCredentials
instance to store the new values:
- access token
- refresh token
- expiry time (created_at + expires_in)
- use that method before making a `gl = Gitlab(...) call when the oauth credentials expiry is None (as currently) or expired