Developer Documentation
Getting Started
Overview
This guide is for developers of an application that connects to OneAccess. By the end you will have registered an application, obtained a token and made a first call.
Four things are kept separate:
- This public documentation explains the protocol and shows examples. It needs no sign-in.
- The Developer Portal is where you register applications, manage credentials and request approval. It needs a sign-in.
- Development and Test configuration is for building and validating your integration.
- Production configuration needs approval and uses strict settings.
Placeholders such as YOUR_CLIENT_ID and API_BASE_URL stand for values you obtain yourself. Nothing on this page is a working credential.
Prerequisites
- A OneAccess account that is a member of a developer group. That membership is what grants access to the Developer Portal; without it the portal refuses you.
- An application that can make HTTPS requests and keep a secret on the server.
- The exact HTTPS redirect URIs of your application, if it signs users in. OneAccess compares them by exact string match; there are no wildcards.
- A secret store for the client secret. Never commit it, log it or send it to a browser.
Register an application
Registration happens in the Developer Portal, not here. Choose the application type that matches what you are building:
| Type | Flow | Client secret | Redirect URIs |
|---|---|---|---|
| Web | Authorization Code with PKCE | Yes (confidential) | Required |
| Service | Client Credentials | Yes | Not allowed |
Use a separate registration, and a separate client identifier, in each environment. A Production registration must be approved before a credential can be issued. The portal also offers a single-page (public client) type; it is described in the portal documentation and is not covered by this reference.
Choose a flow
| You are building | Use | Notes |
|---|---|---|
| An application that signs users in | Authorization Code with PKCE | Only S256. Returns an access token and, with the openid scope, an ID token. No refresh token is issued. |
| A back-end service acting as itself | Client Credentials | Service registrations only. Scopes that release user claims are refused. No ID token. |
No other grant is supported. A request with another grant_type is refused with unsupported_grant_type.
Obtain credentials securely
After the registration is active (and approved, for Production), issue the client secret from the Developer Portal. The secret is shown once. Copy it straight into your secret store.
- Keep the secret on the server only. Never place it in browser code, a mobile app, source control, a log or a ticket.
- Rotate it from the portal. A secret has a limited lifetime and an expired or revoked secret is refused with
invalid_client. - Send it only to the token and revocation endpoints, over HTTPS.
Request an access token
Call the token endpoint from your server. Authenticate the client with HTTP Basic, as in these examples, or send client_id and client_secret in the form.
The examples in this guide are curated by hand and are illustrative; they are not generated from the OpenAPI document and are not SDKs. The API Reference shows samples generated for each operation.
Service application: Client Credentials
curl --fail-with-body --request POST "API_BASE_URL/connect/token" \
--user "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "scope=YOUR_SCOPE" \
--data-urlencode "resource=YOUR_API_AUDIENCE"
using System.Net.Http.Headers;
using System.Text;
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "API_BASE_URL/connect/token");
var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes("YOUR_CLIENT_ID:YOUR_CLIENT_SECRET"));
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
request.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "client_credentials",
["scope"] = "YOUR_SCOPE",
["resource"] = "YOUR_API_AUDIENCE",
});
using var response = await http.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
// Branch on the status and the OAuth "error" code; log X-Correlation-ID, never a token or secret.
throw new HttpRequestException($"Request failed with status {(int)response.StatusCode}.");
}
var body = await response.Content.ReadAsStringAsync();
const credentials = Buffer.from("YOUR_CLIENT_ID:YOUR_CLIENT_SECRET").toString("base64");
const response = await fetch("API_BASE_URL/connect/token", {
method: "POST",
headers: {
Authorization: `Basic ${credentials}`,
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
grant_type: "client_credentials",
scope: "YOUR_SCOPE",
resource: "YOUR_API_AUDIENCE",
}),
});
if (!response.ok) {
// Branch on the status and the OAuth "error" code; log X-Correlation-ID, never a token or secret.
throw new Error(`Request failed with status ${response.status}`);
}
const body = await response.json();
// Server-side runtime only (Deno, Bun, a worker). Never put a client secret in browser code.
const credentials = btoa("YOUR_CLIENT_ID:YOUR_CLIENT_SECRET");
const response = await fetch("API_BASE_URL/connect/token", {
method: "POST",
headers: {
Authorization: `Basic ${credentials}`,
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
grant_type: "client_credentials",
scope: "YOUR_SCOPE",
resource: "YOUR_API_AUDIENCE",
}),
});
if (!response.ok) {
// Branch on the status and the OAuth "error" code; log X-Correlation-ID, never a token or secret.
throw new Error(`Request failed with status ${response.status}`);
}
const body = await response.json();
import requests
response = requests.post(
"API_BASE_URL/connect/token",
auth=("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET"),
data={
"grant_type": "client_credentials",
"scope": "YOUR_SCOPE",
"resource": "YOUR_API_AUDIENCE",
},
)
response.raise_for_status() # branch on the status and the OAuth "error" code; never log a token or secret
body = response.json()
library(httr)
response <- POST(
"API_BASE_URL/connect/token",
authenticate("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", type = "basic"),
body = list(grant_type = "client_credentials", scope = "YOUR_SCOPE", resource = "YOUR_API_AUDIENCE"),
encode = "form"
)
stop_for_status(response) # branch on the status and the OAuth "error" code; never log a token or secret
body <- content(response, as = "parsed")
require "net/http"
require "json"
uri = URI("API_BASE_URL/connect/token")
request = Net::HTTP::Post.new(uri)
request.basic_auth("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
request.set_form_data(
"grant_type" => "client_credentials",
"scope" => "YOUR_SCOPE",
"resource" => "YOUR_API_AUDIENCE"
)
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
raise "Request failed with status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
body = JSON.parse(response.body)
<?php
$curl = curl_init("API_BASE_URL/connect/token");
$options = [CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_USERPWD => "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET", CURLOPT_POSTFIELDS => http_build_query(["grant_type" => "client_credentials", "scope" => "YOUR_SCOPE", "resource" => "YOUR_API_AUDIENCE"])];
curl_setopt_array($curl, $options);
$raw = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("Request failed with status $status");
}
$body = json_decode($raw, true);
package main
import (
"io"
"net/http"
"net/url"
"strings"
)
func main() {
form := url.Values{}
form.Set("grant_type", "client_credentials")
form.Set("scope", "YOUR_SCOPE")
form.Set("resource", "YOUR_API_AUDIENCE")
request, _ := http.NewRequest("POST", "API_BASE_URL/connect/token", strings.NewReader(form.Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
request.SetBasicAuth("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
response, err := http.DefaultClient.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode > 299 {
panic("request failed: " + response.Status)
}
body, _ := io.ReadAll(response.Body)
_ = body
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;
String credentials = Base64.getEncoder().encodeToString("YOUR_CLIENT_ID:YOUR_CLIENT_SECRET".getBytes());
String form = "grant_type=client_credentials&scope=YOUR_SCOPE&resource=YOUR_API_AUDIENCE";
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create("API_BASE_URL/connect/token"))
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", "Basic " + credentials)
.POST(HttpRequest.BodyPublishers.ofString(form));
HttpResponse<String> response = HttpClient.newHttpClient()
.send(builder.build(), HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 200 || response.statusCode() > 299) {
throw new RuntimeException("Request failed with status " + response.statusCode());
}
The scope must be approved and granted to your registration. When the scope belongs to an API, also send that API's audience as resource. It must be an absolute URI and registered for your application. Cache the token until shortly before expires_in elapses rather than requesting one per call.
Signing users in: Authorization Code with PKCE
Create a random code_verifier, derive code_challenge as the Base64URL SHA-256 of it, and redirect the user's browser to the authorization endpoint:
API_BASE_URL/connect/authorize
?response_type=code
&client_id=YOUR_CLIENT_ID
&redirect_uri=YOUR_REDIRECT_URI
&scope=openid%20profile
&state=YOUR_STATE
&nonce=YOUR_NONCE
&code_challenge=YOUR_CODE_CHALLENGE
&code_challenge_method=S256
After sign-in the browser returns to your redirect_uri with code and your state. Check state, then exchange the code from your server. A code is single-use and expires after five minutes.
Validate the ID token (signature from the published keys, issuer, audience and nonce) before trusting it. Use an OpenID Connect library where you can; it performs these steps for you.
The response
{
"access_token": "YOUR_ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600,
"id_token": "YOUR_ID_TOKEN"
}
id_token appears only for an authorization-code request that included openid. Treat both tokens as secrets.
Make the first protected request
Send the access token of a signed-in user to the UserInfo endpoint. It returns the approved claims that the token's scopes allow.
curl --fail-with-body --request GET "API_BASE_URL/connect/userinfo" \
--header "Authorization: Bearer YOUR_ACCESS_TOKEN"
using System.Net.Http.Headers;
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "API_BASE_URL/connect/userinfo");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_ACCESS_TOKEN");
using var response = await http.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
// Branch on the status and the OAuth "error" code; log X-Correlation-ID, never a token or secret.
throw new HttpRequestException($"Request failed with status {(int)response.StatusCode}.");
}
var body = await response.Content.ReadAsStringAsync();
const response = await fetch("API_BASE_URL/connect/userinfo", {
method: "GET",
headers: {
Authorization: "Bearer YOUR_ACCESS_TOKEN",
},
});
if (!response.ok) {
// Branch on the status and the OAuth "error" code; log X-Correlation-ID, never a token or secret.
throw new Error(`Request failed with status ${response.status}`);
}
const body = await response.json();
const response = await fetch("API_BASE_URL/connect/userinfo", {
method: "GET",
headers: {
Authorization: "Bearer YOUR_ACCESS_TOKEN",
},
});
if (!response.ok) {
// Branch on the status and the OAuth "error" code; log X-Correlation-ID, never a token or secret.
throw new Error(`Request failed with status ${response.status}`);
}
const body = await response.json();
import requests
response = requests.get(
"API_BASE_URL/connect/userinfo",
headers={"Authorization": "Bearer YOUR_ACCESS_TOKEN"},
)
response.raise_for_status() # branch on the status and the OAuth "error" code; never log a token or secret
body = response.json()
library(httr)
response <- GET(
"API_BASE_URL/connect/userinfo",
add_headers(Authorization = "Bearer YOUR_ACCESS_TOKEN")
)
stop_for_status(response) # branch on the status and the OAuth "error" code; never log a token or secret
body <- content(response, as = "parsed")
require "net/http"
require "json"
uri = URI("API_BASE_URL/connect/userinfo")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer YOUR_ACCESS_TOKEN"
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
raise "Request failed with status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
body = JSON.parse(response.body)
<?php
$curl = curl_init("API_BASE_URL/connect/userinfo");
$options = [CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => ["Authorization: Bearer YOUR_ACCESS_TOKEN"]];
curl_setopt_array($curl, $options);
$raw = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("Request failed with status $status");
}
$body = json_decode($raw, true);
package main
import (
"io"
"net/http"
)
func main() {
request, _ := http.NewRequest("GET", "API_BASE_URL/connect/userinfo", nil)
request.Header.Set("Authorization", "Bearer YOUR_ACCESS_TOKEN")
response, err := http.DefaultClient.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode > 299 {
panic("request failed: " + response.Status)
}
body, _ := io.ReadAll(response.Body)
_ = body
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create("API_BASE_URL/connect/userinfo"))
.header("Authorization", "Bearer YOUR_ACCESS_TOKEN")
.GET();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(builder.build(), HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 200 || response.statusCode() > 299) {
throw new RuntimeException("Request failed with status " + response.statusCode());
}
Use the sub claim, not the email address, to key your own records. UserInfo is meant for user-delegated tokens. An API of your own validates the access token itself and checks its own scopes; OneAccess does not call it for you.
Handle success and errors
Branch on the HTTP status first, then on the error code. Four shapes exist:
| Where | Status | Shape |
|---|---|---|
| Token and revocation | 400, 401 | JSON with error and error_description. A 401 carries WWW-Authenticate: Basic. |
| Authorization endpoint | 400, 401 | Plain text, one key:value line each for error and error_description. It is not JSON. |
| UserInfo | 401 | No body; WWW-Authenticate: Bearer. |
| Unexpected failure | 500 | Problem Details (application/problem+json) with a correlationId. |
{
"error": "invalid_client",
"error_description": "The client authentication or registration is not valid."
}
{
"type": "about:blank",
"title": "An unexpected error occurred.",
"status": 500,
"detail": "The request could not be completed.",
"instance": "/connect/token",
"correlationId": "0f8fad5bd9cb469fa16570867728950e"
}
Match on the error code; error_description is diagnostic text. Log it and the correlationId, and show your users a message of your own. No operation in this reference paginates, filters or sorts, and no rate-limit response is defined.
Environments
OneAccess has three environments: Development, Test and Production. There is no Staging environment. Use Test for a production-like check. Each environment has its own base address (the issuer in its discovery document at /.well-known/openid-configuration), its own registration and its own secret. Never reuse a Production secret elsewhere. Use the address of the OneAccess deployment for the environment you are working in.
Production readiness
- The Production registration is approved and uses exact HTTPS redirect URIs.
- The client secret is in a secret store and is never logged.
- PKCE (
S256),stateandnonceare used and checked. - ID tokens are validated; access tokens are validated by your APIs.
- Tokens are kept out of browser storage and out of logs.
- Errors are handled by code, and
correlationIdis logged with each failure. - Your own session ends when the user signs out of your application.
- Tokens are cached until shortly before expiry, not requested per call.