OpenID Connect
Get User Info
Get information about the authenticated user.
GET
/
v1
/
oauth2
/
userinfo
Go (SDK)
package main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"log"
"github.com/polarsource/polar-go/models/operations"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Oauth2.Userinfo(ctx)
if err != nil {
log.Fatal(err)
}
if res.ResponseOauth2Userinfo != nil {
switch res.ResponseOauth2Userinfo.Type {
case operations.Oauth2UserinfoResponseOauth2UserinfoTypeUserInfoUser:
// res.ResponseOauth2Userinfo.UserInfoUser is populated
case operations.Oauth2UserinfoResponseOauth2UserinfoTypeUserInfoOrganization:
// res.ResponseOauth2Userinfo.UserInfoOrganization is populated
}
}
}from polar_sdk import Polar
with Polar(
access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:
res = polar.oauth2.userinfo()
# Handle response
print(res)import { Polar } from "@polar-sh/sdk";
const polar = new Polar({
accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});
async function run() {
const result = await polar.oauth2.userinfo();
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->oauth2->userinfo(
);
if ($response->responseOauth2Userinfo !== null) {
// handle response
}curl --request GET \
--url https://api.polar.sh/v1/oauth2/userinfo \
--header 'Authorization: Bearer <token>'const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.polar.sh/v1/oauth2/userinfo', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.get("https://api.polar.sh/v1/oauth2/userinfo")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polar.sh/v1/oauth2/userinfo")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"sub": "<string>",
"name": "<string>",
"email": "<string>",
"email_verified": true
}Was this page helpful?
⌘I
Go (SDK)
package main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"log"
"github.com/polarsource/polar-go/models/operations"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Oauth2.Userinfo(ctx)
if err != nil {
log.Fatal(err)
}
if res.ResponseOauth2Userinfo != nil {
switch res.ResponseOauth2Userinfo.Type {
case operations.Oauth2UserinfoResponseOauth2UserinfoTypeUserInfoUser:
// res.ResponseOauth2Userinfo.UserInfoUser is populated
case operations.Oauth2UserinfoResponseOauth2UserinfoTypeUserInfoOrganization:
// res.ResponseOauth2Userinfo.UserInfoOrganization is populated
}
}
}from polar_sdk import Polar
with Polar(
access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:
res = polar.oauth2.userinfo()
# Handle response
print(res)import { Polar } from "@polar-sh/sdk";
const polar = new Polar({
accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});
async function run() {
const result = await polar.oauth2.userinfo();
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->oauth2->userinfo(
);
if ($response->responseOauth2Userinfo !== null) {
// handle response
}curl --request GET \
--url https://api.polar.sh/v1/oauth2/userinfo \
--header 'Authorization: Bearer <token>'const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.polar.sh/v1/oauth2/userinfo', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.get("https://api.polar.sh/v1/oauth2/userinfo")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polar.sh/v1/oauth2/userinfo")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"sub": "<string>",
"name": "<string>",
"email": "<string>",
"email_verified": true
}
