Connect with OAuth

Ask a creator for access with OAuth 2.1 and PKCE, and get a token for the Linky Hub API.

Embed
Preview of the card
<a href="https://linkyhub.net/docs/oauth"><img src="https://linkyhub.net/docs/_api/public/orgs/2fd2a4b7-b627-4925-af1e-1c51bf890403/spaces/c4b920fb-a433-40b5-b354-ff84bf0c3eb1/pages/32bef251-fd1e-42f7-bb32-44d18c95c66d/social-card.svg?v=3e7ae33eec8b" alt="Connect with OAuth" width="600" height="315"></a>

Linky Hub's authorization server is at https://linkyhub.net/atlas. Point your OAuth library at its discovery document rather than hard-coding paths:

GET $LINKHUB_URL/atlas/.well-known/openid-configuration

1. Send the creator to authorize

Use the authorization code flow with PKCE (S256). Ask for openid plus the scopes you need, and name the Linky Hub API as the resource:

$LINKHUB_URL/atlas/oauth2/authorize
  ?response_type=code
  &client_id=YOUR_CLIENT_ID
  &redirect_uri=https://yourapp.example/callback
  &scope=openid%20products:read%20inventory:write
  &resource=urn:linkhub:api
  &state=RANDOM
  &code_challenge=BASE64URL_SHA256_OF_VERIFIER
  &code_challenge_method=S256

The creator signs in to Linky Hub and sees a consent page listing every scope in plain words. They can untick any scope except openid. Read the scope of the token you get back; never assume you got everything you asked for.

2. Exchange the code

curl -X POST "$LINKHUB_URL/atlas/oauth2/token" \
  -d grant_type=authorization_code \
  -d code=THE_CODE \
  -d redirect_uri=https://yourapp.example/callback \
  -d client_id=YOUR_CLIENT_ID \
  -d client_secret=YOUR_CLIENT_SECRET \
  -d code_verifier=THE_VERIFIER \
  -d resource=urn:linkhub:api

The access token is a JWT for the audience urn:linkhub:api and lasts an hour. Ask for offline_access too if you need a refresh token.

3. Refresh

curl -X POST "$LINKHUB_URL/atlas/oauth2/token" \
  -d grant_type=refresh_token \
  -d refresh_token=THE_REFRESH_TOKEN \
  -d client_id=YOUR_CLIENT_ID \
  -d client_secret=YOUR_CLIENT_SECRET

Do not treat a 401 from the API as fatal: refresh once and retry.

4. Revoke

When the creator disconnects inside your app, revoke the refresh token at the revocation_endpoint from discovery. Creators can also disconnect your app from Apps in their Linky Hub dashboard; your tokens then stop working at once.

Apps with no browser

Devices and command-line tools use the device authorization grant (RFC 8628) at the device_authorization_endpoint from discovery.

Updated