OpenID Connect
Request Token
Request an access token using a valid grant.
POST
/
v1
/
oauth2
/
token
Go (SDK)
package main
import(
"context"
polargo "github.com/polarsource/polar-go"
"github.com/polarsource/polar-go/models/components"
"github.com/polarsource/polar-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := polargo.New()
res, err := s.Oauth2.Token(ctx, operations.CreateOauth2RequestTokenRequestBodyAuthorizationCodeTokenRequest(
components.AuthorizationCodeTokenRequest{
ClientID: "<id>",
ClientSecret: "<value>",
Code: "<value>",
RedirectURI: "https://memorable-season.name",
},
))
if err != nil {
log.Fatal(err)
}
if res.TokenResponse != nil {
// handle response
}
}from polar_sdk import Polar
with Polar() as polar:
res = polar.oauth2.token(request={
"grant_type": "authorization_code",
"client_id": "<id>",
"client_secret": "<value>",
"code": "<value>",
"redirect_uri": "https://memorable-season.name",
})
# Handle response
print(res)import { Polar } from "@polar-sh/sdk";
const polar = new Polar();
async function run() {
const result = await polar.oauth2.token({
grantType: "authorization_code",
clientId: "<id>",
clientSecret: "<value>",
code: "<value>",
redirectUri: "https://memorable-season.name",
});
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Components;
$sdk = Polar\Polar::builder()->build();
$request = new Components\AuthorizationCodeTokenRequest(
clientId: '<id>',
clientSecret: '<value>',
code: '<value>',
redirectUri: 'https://memorable-season.name',
);
$response = $sdk->oauth2->token(
request: $request
);
if ($response->tokenResponse !== null) {
// handle response
}curl --request POST \
--url https://api.polar.sh/v1/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'grant_type=<string>' \
--data 'client_id=<string>' \
--data 'client_secret=<string>' \
--data 'code=<string>' \
--data 'redirect_uri=<string>'const options = {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
grant_type: '<string>',
client_id: '<string>',
client_secret: '<string>',
code: '<string>',
redirect_uri: '<string>'
})
};
fetch('https://api.polar.sh/v1/oauth2/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.polar.sh/v1/oauth2/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=%3Cstring%3E&client_id=%3Cstring%3E&client_secret=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polar.sh/v1/oauth2/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=%3Cstring%3E&client_id=%3Cstring%3E&client_secret=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"token_type": "<string>",
"expires_in": 123,
"scope": "<string>",
"refresh_token": "<string>",
"id_token": "<string>"
}Body
application/x-www-form-urlencoded
Was this page helpful?
⌘I
Go (SDK)
package main
import(
"context"
polargo "github.com/polarsource/polar-go"
"github.com/polarsource/polar-go/models/components"
"github.com/polarsource/polar-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := polargo.New()
res, err := s.Oauth2.Token(ctx, operations.CreateOauth2RequestTokenRequestBodyAuthorizationCodeTokenRequest(
components.AuthorizationCodeTokenRequest{
ClientID: "<id>",
ClientSecret: "<value>",
Code: "<value>",
RedirectURI: "https://memorable-season.name",
},
))
if err != nil {
log.Fatal(err)
}
if res.TokenResponse != nil {
// handle response
}
}from polar_sdk import Polar
with Polar() as polar:
res = polar.oauth2.token(request={
"grant_type": "authorization_code",
"client_id": "<id>",
"client_secret": "<value>",
"code": "<value>",
"redirect_uri": "https://memorable-season.name",
})
# Handle response
print(res)import { Polar } from "@polar-sh/sdk";
const polar = new Polar();
async function run() {
const result = await polar.oauth2.token({
grantType: "authorization_code",
clientId: "<id>",
clientSecret: "<value>",
code: "<value>",
redirectUri: "https://memorable-season.name",
});
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Components;
$sdk = Polar\Polar::builder()->build();
$request = new Components\AuthorizationCodeTokenRequest(
clientId: '<id>',
clientSecret: '<value>',
code: '<value>',
redirectUri: 'https://memorable-season.name',
);
$response = $sdk->oauth2->token(
request: $request
);
if ($response->tokenResponse !== null) {
// handle response
}curl --request POST \
--url https://api.polar.sh/v1/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'grant_type=<string>' \
--data 'client_id=<string>' \
--data 'client_secret=<string>' \
--data 'code=<string>' \
--data 'redirect_uri=<string>'const options = {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
grant_type: '<string>',
client_id: '<string>',
client_secret: '<string>',
code: '<string>',
redirect_uri: '<string>'
})
};
fetch('https://api.polar.sh/v1/oauth2/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.polar.sh/v1/oauth2/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=%3Cstring%3E&client_id=%3Cstring%3E&client_secret=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polar.sh/v1/oauth2/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=%3Cstring%3E&client_id=%3Cstring%3E&client_secret=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"token_type": "<string>",
"expires_in": 123,
"scope": "<string>",
"refresh_token": "<string>",
"id_token": "<string>"
}
