# Sign in with Tringify

Register a confidential OpenID Connect client and implement Authorization Code with PKCE.

OAuth Apps are confidential OpenID Connect clients for **Sign in with Tringify**. They identify Tringify account users to a server-backed application; they are not installed into stores and their access tokens do not authorize Store API requests.

## Create and activate the client

- Create the OAuth app inside its owning organization. The client secret is displayed once; store it in the application's server-side secret manager.
- Register every redirect URI exactly as it will appear in authorization and token requests. Public callbacks require HTTPS; loopback HTTP callbacks are accepted for local development.
- Activate the client. Activation requires an approved developer profile and at least one registered redirect URI. Draft and disabled clients cannot authorize or exchange codes.

## Discover the OpenID configuration

Use `https://api.tringify.com/.well-known/openid-configuration` as the source of the authorization, token, UserInfo, and JWKS endpoints and the current issuer. At publication, the issuer is `https://accounts.tringify.com`; protocol endpoints are on `https://api.tringify.com`.

> The authorization endpoint validates the client and redirect URI, then sends the browser to Tringify Accounts. Accounts authenticates the user and records consent. Your backend exchanges the returned code at the `token_endpoint` from discovery; it never sends the client secret to Accounts.

## Start authorization

```text
GET {authorization_endpoint}?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_EXACT_REDIRECT_URI&scope=openid%20email&state=FRESH_STATE&nonce=FRESH_NONCE&code_challenge=BASE64URL_SHA256_VERIFIER&code_challenge_method=S256
```

Generate independent, unpredictable `state`, `nonce`, and PKCE verifier values for each authorization request and retain them in the initiating server session. Request `openid`; add `profile` and `email` only when required. Only these three grant access; any other scope value grants nothing and is not shown on the consent screen. The user sees each requested scope's name and what it shares on the consent screen, and later on Accounts › Connected apps. Redirect URIs are matched byte for byte.

## Validate the callback

The callback contains `code`, `state`, and `iss`. Reject a missing or mismatched `state` or issuer before exchanging the code. Authorization codes are single-use and expire after 10 minutes.

## Exchange the code

```bash
curl -X POST https://api.tringify.com/oauth/token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=authorization_code' \
  --data-urlencode 'client_id=YOUR_CLIENT_ID' \
  --data-urlencode 'client_secret=YOUR_CLIENT_SECRET' \
  --data-urlencode 'code=CODE_FROM_CALLBACK' \
  --data-urlencode 'redirect_uri=YOUR_EXACT_REDIRECT_URI' \
  --data-urlencode 'code_verifier=YOUR_ORIGINAL_CODE_VERIFIER'
```

Send `client_secret` in the form body (`client_secret_post`); HTTP Basic client authentication is not accepted. Verify the `id_token` with the discovery document's `jwks_uri`. Validate its signature with the key its `kid` names, using that key's `alg` (today `RS256`; take it from the key rather than hard-coding it), and its `iss`, `aud`, `exp`, and `nonce`; reject a nonce that does not match the initiating authorization request. The ID token is valid for 1 hour. `sub` is always present; `name` requires the `profile` scope; `email` and `email_verified` require the `email` scope, and `email_verified` is omitted when the address is unverified. The access token is an opaque bearer token valid for 1 hour, and its only use is the discovered `userinfo_endpoint`; it does not authorize any other Tringify API. Third-party OAuth Apps do not receive refresh tokens; reauthorize when identity must be established again.

## Add the sign-in button

Render **Sign in with Tringify** as a plain link to your own server route that starts authorization. Use the Tringify mark at `https://accounts.tringify.com/brand/v1/tringify-leather-white.webp` on a black button; the URL is versioned and safe to hot-link.

```html
<a href="/auth/tringify/start"
  style="display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; background: #000; color: #fff; border-radius: 8px; font-weight: 500; font-size: 14px; text-decoration: none;">
  <img src="https://accounts.tringify.com/brand/v1/tringify-leather-white.webp" alt="Tringify" width="20" height="20">
  Sign in with Tringify
</a>
```

## Disable, rotate, or delete

Disabling a client immediately blocks new authorization, code exchange, and UserInfo requests. An ID token already issued remains independently verifiable until its `exp`. Rotating the client secret keeps the previous secret valid for 72 hours so you can deploy the new one; finish the rotation in the Developer Portal to revoke it sooner. Rotation does not revoke existing access tokens or grants. Deleting the client is permanent, removes its server-side authorization data, and requires organization identity verification.

