OAuth
Trade an authorization code or refresh token for tokens, and revoke refresh tokens. See Getting Started for the whole sign-in flow.
Background and examples: Getting Started
Get tokens
/v1/oauth/token
OAuth 2.0 token endpoint. Exchanges authorization codes or refresh tokens for access tokens. Supports two grant types: authorization_code and refresh_token.
No token needed.
Request body application/x-www-form-urlencoded
-
grant_typestring required authorization_code to trade a code from the sign-in page, or refresh_token to refresh.
-
client_iduuid required The OAuth client's id.
-
client_secretstring required The OAuth client's secret. Keep it on your server.
-
redirect_uristring With authorization_code: the redirect URL used to sign in, exactly as registered.
-
codestring With authorization_code: the code the sign-in page sent to your redirect URL.
-
refresh_tokenstring With refresh_token: the refresh token to trade for a new pair.
Responses
- 200 Returns the access token, refresh token, and expiration time.
- 400 If the grant type is invalid, authorization code is invalid, redirect URI doesn't exactly match a registered one, or other validation errors occur.
- 401 If the client secret doesn't match the client ID.
Request
curl -X POST 'https://api.stellards.io/v1/oauth/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=authorization_code&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&redirect_uri=REDIRECT_URI&code=AUTHORIZATION_CODE'
const response = await fetch("https://api.stellards.io/v1/oauth/token", {
method: "POST",
body: new URLSearchParams({
grant_type: "authorization_code",
client_id: "CLIENT_ID",
client_secret: "CLIENT_SECRET",
redirect_uri: "REDIRECT_URI",
code: "AUTHORIZATION_CODE",
}),
});
const result = await response.json();
console.log(result);
import requests
response = requests.post(
"https://api.stellards.io/v1/oauth/token",
data={
"grant_type": "authorization_code",
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
"redirect_uri": "REDIRECT_URI",
"code": "AUTHORIZATION_CODE",
},
)
print(response.json())
using System.Net.Http.Headers;
using var client = new HttpClient();
var body = new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "authorization_code",
["client_id"] = "CLIENT_ID",
["client_secret"] = "CLIENT_SECRET",
["redirect_uri"] = "REDIRECT_URI",
["code"] = "AUTHORIZATION_CODE",
});
var response = await client.PostAsync("https://api.stellards.io/v1/oauth/token", body);
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
Form: TStringList;
begin
Client := THTTPClient.Create;
Form := TStringList.Create;
Form.Values['grant_type'] := 'authorization_code';
Form.Values['client_id'] := 'CLIENT_ID';
Form.Values['client_secret'] := 'CLIENT_SECRET';
Form.Values['redirect_uri'] := 'REDIRECT_URI';
Form.Values['code'] := 'AUTHORIZATION_CODE';
try
Response := Client.Post('https://api.stellards.io/v1/oauth/token', Form);
Writeln(Response.ContentAsString);
finally
Form.Free;
Client.Free;
end;
end;
Response 200
{
"access_token": "eyJhbGciOi...",
"refresh_token": "eyJhbGciOi...",
"expires_in": 1770,
"token_type": "Bearer"
}
Revoke a refresh token
/v1/oauth/revoke
Revokes an OAuth refresh token, invalidating it and preventing it from being used to obtain new access tokens.
No token needed.
Request body application/json
The revoke request containing client credentials and the refresh token to revoke.
- ClientId: The GUID of the OAuth client.
- ClientSecret: The client secret for authentication.
- Refresh: The refresh token hash to revoke.
-
refresh_tokenstring required The refresh token to revoke.
-
client_iduuid required The OAuth client's id.
-
client_secretstring required The OAuth client's secret.
Responses
- 200 The refresh token was successfully revoked.
- 400 If the client ID is not found, refresh token is not found, or validation fails.
- 401 If the client secret doesn't match the client ID.
Request
curl -X POST 'https://api.stellards.io/v1/oauth/revoke' \
-H 'Content-Type: application/json' \
-d '{
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
"refresh_token": "REFRESH_TOKEN"
}'
const response = await fetch("https://api.stellards.io/v1/oauth/revoke", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
"refresh_token": "REFRESH_TOKEN"
}),
});
const result = await response.json();
console.log(result);
import requests
response = requests.post(
"https://api.stellards.io/v1/oauth/revoke",
json={
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
"refresh_token": "REFRESH_TOKEN",
},
)
print(response.json())
using System.Net.Http.Headers;
using System.Text;
using var client = new HttpClient();
var body = new StringContent("""
{
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
"refresh_token": "REFRESH_TOKEN"
}
""", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.stellards.io/v1/oauth/revoke", body);
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
Body: TStringStream;
begin
Client := THTTPClient.Create;
Body := TStringStream.Create(
'{' +
' "client_id": "CLIENT_ID",' +
' "client_secret": "CLIENT_SECRET",' +
' "refresh_token": "REFRESH_TOKEN"' +
'}',
TEncoding.UTF8);
try
Client.ContentType := 'application/json';
Response := Client.Post('https://api.stellards.io/v1/oauth/revoke', Body);
Writeln(Response.ContentAsString);
finally
Body.Free;
Client.Free;
end;
end;