curl --request POST \
--url https://api.portalhq.io/api/v3/auth/oauth/tokens \
--header 'Content-Type: application/json' \
--header 'x-portal-auth-environment-id: <api-key>' \
--data '
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token"
}
'import requests
url = "https://api.portalhq.io/api/v3/auth/oauth/tokens"
payload = { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token" }
headers = {
"x-portal-auth-environment-id": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-portal-auth-environment-id': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token'})
};
fetch('https://api.portalhq.io/api/v3/auth/oauth/tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.portalhq.io/api/v3/auth/oauth/tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-portal-auth-environment-id: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.portalhq.io/api/v3/auth/oauth/tokens"
payload := strings.NewReader("{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-portal-auth-environment-id", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.portalhq.io/api/v3/auth/oauth/tokens")
.header("x-portal-auth-environment-id", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.portalhq.io/api/v3/auth/oauth/tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-portal-auth-environment-id"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"endUserId": "clx1enduser00000000000000",
"clientId": "clx1client00000000000000",
"clientSessionToken": "b7c1f0a2-3d4e-5f60-8a91-2b3c4d5e6f70",
"isAccountAbstracted": false,
"userJwt": null,
"totpLink": null
},
"metadata": null
}Validate an OAuth token
Exchanges the single-use token returned to your redirectUrl after a
Google or Apple sign-in for a session.
The response depends on whether the environment requires two-factor
authentication. See the EndUserAuthResult schema for the three shapes
and how to branch on them.
curl --request POST \
--url https://api.portalhq.io/api/v3/auth/oauth/tokens \
--header 'Content-Type: application/json' \
--header 'x-portal-auth-environment-id: <api-key>' \
--data '
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token"
}
'import requests
url = "https://api.portalhq.io/api/v3/auth/oauth/tokens"
payload = { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token" }
headers = {
"x-portal-auth-environment-id": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-portal-auth-environment-id': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token'})
};
fetch('https://api.portalhq.io/api/v3/auth/oauth/tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.portalhq.io/api/v3/auth/oauth/tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-portal-auth-environment-id: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.portalhq.io/api/v3/auth/oauth/tokens"
payload := strings.NewReader("{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-portal-auth-environment-id", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.portalhq.io/api/v3/auth/oauth/tokens")
.header("x-portal-auth-environment-id", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.portalhq.io/api/v3/auth/oauth/tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-portal-auth-environment-id"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.example.token\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"endUserId": "clx1enduser00000000000000",
"clientId": "clx1client00000000000000",
"clientSessionToken": "b7c1f0a2-3d4e-5f60-8a91-2b3c4d5e6f70",
"isAccountAbstracted": false,
"userJwt": null,
"totpLink": null
},
"metadata": null
}Authorizations
The Auth Environment ID for the environment you are authenticating against. Find it in the Portal dashboard under Authentication > Configure.
Body
The single-use token query parameter Portal appended to your
redirect URL.
Response
Token validated successfully
The outcome of a sign-in. Which fields are set depends on whether the environment requires two-factor authentication:
- Two-factor not required.
clientId,clientSessionTokenandisAccountAbstractedare set,userJwtandtotpLinkarenull. The sign-in is complete. - Two-factor required, user already enrolled.
userJwtis set,clientId,clientSessionToken,isAccountAbstractedandtotpLinkarenull. Prompt for a code and callPOST /totps/validations. - Two-factor required, first sign-in.
userJwtandtotpLinkare both set,clientId,clientSessionTokenandisAccountAbstractedarenull. RendertotpLinkas a QR code for the user to scan, then prompt for a code and callPOST /totps/validations.
Branch on clientSessionToken being non-null to decide whether the
sign-in is finished. The client fields are only populated once the
sign-in completes, so on the two-factor branches they arrive with the
POST /totps/validations response instead.
Show child attributes
Show child attributes
Always null for this endpoint.
Was this page helpful?