Connect a Tip4Serv user, store the access token safely, reuse it later, and disconnect cleanly.
This demo uses the real browser-side OAuth flow with no backend. Clicking connect redirects to Tip4Serv authorization and returns to this page after approval. The token button only works once a real token has been saved.
Starts the Tip4Serv OAuth authorization flow and redirects the browser to the authorization page.
await Tip4Serv.OAuth.Connect({
return_url: "https://example.com/oauth/callback"
});
Validates the token format and lifetime before saving it to local storage. If token is omitted, it reads tip4serv_access_token from the URL query.
Tip4Serv.OAuth.Save({
token: accessToken
});
Returns the saved token. Throws if none is stored or if the stored token is no longer valid.
const token = Tip4Serv.OAuth.Token();
Clears the stored OAuth token and local OAuth session data.
Tip4Serv.OAuth.Disconnect();
| Method | Arguments | Behavior |
|---|---|---|
| Connect() | { return_url: string, store_id?: number } | Validates the store ID from store_id or the script tag, validates the callback URL, registers a public OAuth client, generates PKCE values, stores the state locally, then redirects the browser. |
| Save() | { token?: string } | Ensures the token is a decodable JWT and rejects expired or not-yet-active tokens before storage. If token is omitted, it falls back to tip4serv_access_token in the URL query. |
| Token() | None | Loads the stored token, validates it again, and returns it as a string. |
| Disconnect() | None | Removes the stored token, registered OAuth client cache, PKCE verifier, and CSRF state. |
<button id="connectButton">Connect Tip4Serv</button>
<script>
document.getElementById("connectButton").addEventListener("click", async () => {
await Tip4Serv.OAuth.Connect({
return_url: "https://example.com/oauth/callback"
});
});
</script>
On your callback URL, simply run this line. If tip4serv_access_token is present in the query, the token is saved and you can access it later with Tip4Serv.OAuth.Token().
Tip4Serv.OAuth.Save();
In this example, we are fetching user payments. To learn more about other routes, check this: https://tip4serv.gitbook.io/tip4serv-api/log-in-via-tip4serv
const token = Tip4Serv.OAuth.Token();
const response = await fetch("https://api.tip4serv.com/v1/user/payments?page=1", {
headers: {
Authorization: `Bearer ${token}`
}
});