Skip to main content
ICT Authority, Kenya: OneAccess API Documentation home

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:

Application types covered by this reference
TypeFlowClient secretRedirect URIs
WebAuthorization Code with PKCEYes (confidential)Required
ServiceClient CredentialsYesNot 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

Supported flows
You are buildingUseNotes
An application that signs users inAuthorization Code with PKCEOnly S256. Returns an access token and, with the openid scope, an ID token. No refresh token is issued.
A back-end service acting as itselfClient CredentialsService 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"

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.

curl --fail-with-body --request POST "API_BASE_URL/connect/token" \
  --user "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  --data-urlencode "grant_type=authorization_code" \
  --data-urlencode "code=YOUR_AUTHORIZATION_CODE" \
  --data-urlencode "redirect_uri=YOUR_REDIRECT_URI" \
  --data-urlencode "code_verifier=YOUR_CODE_VERIFIER"

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"

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:

Error shapes
WhereStatusShape
Token and revocation400, 401JSON with error and error_description. A 401 carries WWW-Authenticate: Basic.
Authorization endpoint400, 401Plain text, one key:value line each for error and error_description. It is not JSON.
UserInfo401No body; WWW-Authenticate: Bearer.
Unexpected failure500Problem 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), state and nonce are 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 correlationId is 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.

Open the API Reference