Skip to content

Commit 5c56a3f

Browse files
update the refresh token docs to have manual refresh
1 parent 7726fe9 commit 5c56a3f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/organization/integrations/integration-platform/public-integration.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,46 @@ def refresh_token(install_id):
108108
return new_token
109109
```
110110

111+
### Refreshing Tokens Manually for Integrators
112+
Sometimes incidents or other technical anomalies can lead to token refreshing being committed on the Sentry side but then the token is lost in transmission on the way back. As a result, we've added a method for integrators to explicitly refresh and request a new token for their installers.
113+
114+
This manual refresh method uses a different authorization scheme where you will need to send a JWT signed with your client secret to the previous
115+
`/api/0/sentry-app-installations/{}/authorizations/` endpoint with the below claims and payload.
116+
117+
```python
118+
def manual_token_refresh(install_id):
119+
url = u'https://sentry.io/api/0/sentry-app-installations/{}/authorizations/'
120+
url = url.format(install_id)
121+
122+
now = datetime.now(timezone.utc).timestamp()
123+
client_secret = "XXXX-XXXX-XXXX"
124+
client_id = "1234-5678-9999"
125+
iat = now
126+
exp = now + 60 # 1 minute validity period
127+
128+
claims = {
129+
'iss': client_id,
130+
'sub': client_id,
131+
'iat': iat,
132+
'exp': exp,
133+
'jti': uuid.uuid4(),
134+
}
135+
jwt_token = jwt.encode(claims, client_secret, algorithm="HS256")
136+
headers = jwt.authorization_header(jwt_token)
137+
138+
payload = {
139+
'grant_type': 'urn:sentry:params:oauth:grant-type:jwt-bearer',
140+
}
141+
resp = requests.post(url, json=payload, headers=headers)
142+
data = resp.json()
143+
144+
new_token = data['token']
145+
new_refresh_token = data['refreshToken']
146+
# ... Securely update the token and refresh_token in DB...
147+
148+
return new_token
149+
```
150+
111151
The data you can expect back for both the initial grant code exchange and subsequent token refreshes is as follows:
112152

113153
```json

0 commit comments

Comments
 (0)