Skip to content

Commit ff36a7f

Browse files
authored
Social SDK: Revoking Tokens (#7670)
Updates to show how to use the new token revocation functions for public clients in the Account Linking with Discord documentation.
1 parent b46279c commit ff36a7f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/discord-social-sdk/development-guides/account-linking-with-discord.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,39 @@ def refresh_token(refresh_token):
230230
231231
If a user wants to disconnect their Discord account or if a token is compromised, you can revoke access and refresh tokens.
232232
233+
:::warn
234+
When any valid access or refresh token is revoked, all of your application's access and refresh tokens for that user are immediately invalidated.
235+
:::
236+
237+
### Revoking Access Tokens for Public Clients
238+
239+
<PublicClient />
240+
241+
The easiest way to revoke tokens is using the SDK's `Client::RevokeToken` method. This will invalidate all access and refresh tokens for the user and they cannot be used again.
242+
243+
```cpp
244+
client->RevokeToken(YOUR_DISCORD_APPLICATION_ID,
245+
accessToken, // Can also use refresh token
246+
[](const discordpp::ClientResult &result) {
247+
if (!result.Successful()) {
248+
std::cout
249+
<< "? Error revoking token: " << result.Error()
250+
<< std::endl;
251+
return;
252+
}
253+
254+
std::cout
255+
<< "? Token successfully revoked! User logged out."
256+
<< std::endl;
257+
// Handle successful logout (clear stored tokens,
258+
// redirect to login, etc.)
259+
});
260+
```
261+
233262
### Server-to-Server Token Revocation
234263
264+
If your application uses a backend server, you can revoke tokens by making an API request to Discord's token revocation endpoint.
265+
235266
```python
236267
import requests
237268

0 commit comments

Comments
 (0)