PKCE proves that the same application that started an authorization also finishes it. Generate a random
code_verifier for every authorization, keep it server-side next to your state, and send its hash as the code_challenge below. The token exchange then requires the original code_verifier, so a stolen callback code is useless on its own.Register your application
1
Create an application
Open the developer portal and create an application. You can own it yourself or assign it to one of your teams.
2
Copy the client ID and client secret
The client secret is shown once when you create it. Store it server-side. You can rotate it later, which invalidates the previous secret immediately.
3
Add redirect URIs
Add every URL Top.gg may redirect back to. Redirect URIs must be absolute
https URLs (or http on loopback for local development) without fragments. Up to 10 per application.Send the user to the authorization page
Redirect the user tohttps://top.gg/oauth2/authorize with the following query parameters:
string
required
Your application’s client ID.
string
required
Must be
code.string
required
One of the redirect URIs registered for your application. Must match exactly.
string
required
The scopes to request, separated by spaces (
+ in the URL). Request only what your application uses. The consent screen lists every scope to the user.string
required
An opaque value you generate per authorization request. Top.gg sends it back unchanged. Verify it on the callback to prevent CSRF.
string
required
PKCE challenge. Generate a random
code_verifier of 43 to 128 characters, then send base64url(sha256(code_verifier)) without padding.string
required
Must be
S256.string
Top.gg project ID to preselect on the consent screen. The user can change the selection. Useful when the user starts the flow from a specific project in your application.
string
Platform for
platform_id, for example discord. Use both together when you know the external ID but not the Top.gg project ID.string
External ID on
platform, for example a Discord bot ID. The matching project is preselected on the consent screen, same behavior as project_id. Unknown IDs are ignored.Handle the callback
On approval, Top.gg redirects to yourredirect_uri:
state before doing anything else. The code is single use and expires after 60 seconds.
Exchange the code for tokens
Call the token endpoint from your backend with the code and the originalcode_verifier:
project is the project the user granted, the same project object GET /projects returns. Refresh responses do not include it.
Store the refresh token securely. The access token is valid for seven days. The full parameter and error reference is on the OAuth endpoints page.
Call the API
Pass the access token as a Bearer token, exactly like a project token:404 or 403 respectively.