Sign users in with OpenID Connect
Your web application sends people to your issuer to sign in and gets back an ID token, an access token, and a refresh token. This page shows the protocol as Authwise speaks it and what to set in any OpenID Connect library. The framework quickstarts at the end apply it in five stacks.
Before you begin
Section titled “Before you begin”- An issuer with at least one realm and sign-in method. See Domains and issuers and Realms.
- A tenant administrator seat, or a service account holding
tenant.admin, to register the client. awctl0.43.0 or later, or Terraform provider 0.35.0 or later, against identity server 1.87.0 or later, if you register the client from the command line. Earlier versions name the commandsidentity clientsandidentity client-secrets, and the resourcesauthwise_clientandauthwise_client_secret.
What the issuer offers
Section titled “What the issuer offers”Every issuer publishes its endpoints and capabilities at the discovery
URL. Replace ISSUER_URL with the issuer’s URL, such as
https://login.example.com:
curl -s ISSUER_URL/.well-known/openid-configuration | jq{ "issuer": "ISSUER_URL", "authorization_endpoint": "ISSUER_URL/authorize", "token_endpoint": "ISSUER_URL/oauth/token", "userinfo_endpoint": "ISSUER_URL/userinfo", "end_session_endpoint": "ISSUER_URL/logout", "jwks_uri": "ISSUER_URL/.well-known/jwks", "introspection_endpoint": "ISSUER_URL/oauth/introspect", "revocation_endpoint": "ISSUER_URL/oauth/revoke", "response_types_supported": ["code"], "response_modes_supported": ["query"], "grant_types_supported": ["authorization_code", "client_credentials", "refresh_token"], "code_challenge_methods_supported": ["S256"], "token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post", "none"], "scopes_supported": ["openid", "profile", "email", "phone", "offline_access"], "id_token_signing_alg_values_supported": ["RS256"], "subject_types_supported": ["public"], "authorization_response_iss_parameter_supported": true, "acr_values_supported": ["urn:authwise:acr:1", "urn:authwise:acr:2", "phr", "phrh"]}What this means for a client library:
- Authorization code only. There is no implicit flow and no hybrid flow. Browser apps use the code flow with PKCE and no secret.
- PKCE is required, with the
S256method. A request without a code challenge is refused. - Three ways to authenticate at the token endpoint. A server-side
application sends its secret with HTTP Basic authentication or in the
form body. A single-page or native application uses
none. - Rotating refresh tokens through the
refresh_tokengrant. - Logout at the end-session endpoint.
- The callback carries
iss, so a library that checks it can tell responses from different issuers apart. scopes_supportedlists the scopes every issuer serves. It never lists an audience’s own scopes, such asroles, because those differ by audience. A scope missing from the list can still be valid for your client.
Discovery is open. Any library that takes an issuer URL configures itself from it.
Read every address from the discovery document, the signing keys
included: they are at jwks_uri, which is ISSUER_URL/.well-known/jwks.
No other path serves them. From identity server 1.98.0, a path the issuer
doesn’t serve under /.well-known, /oauth, /userinfo, /api,
/saml, or /health answers 404 with {"error":"not found"}, so a
wrong address such as /.well-known/jwks.json fails at the first fetch.
Earlier versions answered such a path with status 200 and the sign-in
page’s HTML, which a library can’t parse as keys.
Register a client
Section titled “Register a client”A client is the application’s identity at the issuer. It belongs to an issuer, names an audience whose API the access token is for, and lists the exact redirect URIs the issuer can send a code to.
Decide the client type first:
| Application | Token endpoint authentication | Secret |
|---|---|---|
| Server-rendered web application, or a backend-for-frontend | client_secret_basic | Yes. Create it after creating the client. |
| Single-page application or native application | none | No. PKCE protects the code. |
The console calls a client an application. In the console:
- Go to Issuers, open the issuer, and on the Applications tab click New application.
- Under What kind of application?, select Application.
- In Display name, enter a name for the application.
- In Authentication method, select Secret, Basic header for a confidential client, or leave None (public) for a single-page or native application. Leave the authorization_code and refresh_token grant types on.
- In Audience, select the API the application calls.
- Click Create application, and in the Applications list open the new application.
- Under Where people return after signing in, click Add an address and enter each redirect URI. Under Advanced, open Where people return after signing out and enter the post-logout redirect URIs. Click Save.
- For a confidential client, under Advanced open Secrets, click Create a secret, and then Create. The secret is shown once; copy it and click I have stored it.
The Connect your app card on the application’s page shows the
Application ID, which is the client_id, and the Discovery
address.
Step 7 needs console 0.58.1 or later. On an earlier console, an
application created in the console shows no address lists; set its
redirect URIs with awctl or Terraform instead.
With awctl, a confidential web application:
awctl identity applications create --tenant-id TENANT_ID --issuer-id ISSUER_ID \ --display-name "Web app" --audience-id AUDIENCE_ID --kind APPLICATION_KIND_INTERACTIVE \ --grant-types authorization_code,refresh_token \ --token-endpoint-auth-method client_secret_basic \ --post-logout-redirect-uris https://app.example.com/ \ --config '{"@type":"type.googleapis.com/authwise.types.core.v1alpha1.InteractiveClientConfig","allowed_redirect_uris":["https://app.example.com/callback"]}'awctl identity application-secrets create --tenant-id TENANT_ID --issuer-id ISSUER_ID \ --application-id CLIENT_ID --out client-secret.txtCreated tenants/t-g3wq78hbfjls/issuers/i-g50tkucfpjxv/applications/c-g50tmbajq3poCreated tenants/t-g3wq78hbfjls/issuers/i-g50tkucfpjxv/applications/c-g50tmbajq3po/application-secrets/cs-g50tmbajq3pq (never expires); the secret is in client-secret.txtThis secret is shown once and cannot be retrieved again. Store it now.The ID that the first command prints, c-…, is the client_id your
library sends. Replace CLIENT_ID in the second command with it.
A single-page application is the same command with
--token-endpoint-auth-method none, no secret, and its own redirect URIs,
including the silent-renewal page if it uses one:
awctl identity applications create --tenant-id TENANT_ID --issuer-id ISSUER_ID \ --display-name "Browser app" --audience-id AUDIENCE_ID --kind APPLICATION_KIND_INTERACTIVE \ --grant-types authorization_code,refresh_token \ --token-endpoint-auth-method none \ --post-logout-redirect-uris https://app.example.com/ \ --config '{"@type":"type.googleapis.com/authwise.types.core.v1alpha1.InteractiveClientConfig","allowed_redirect_uris":["https://app.example.com/callback","https://app.example.com/silent-renew.html"]}'Created tenants/t-g3wq78hbfjls/issuers/i-g50tkucfpjxv/applications/c-g50tmbajq3psWith Terraform:
data "authwise_interactive_client_config" "web" { allowed_redirect_uris = ["https://app.example.com/callback"]}
resource "authwise_application" "web" { display_name = "Web app" audience_id = authwise_audience.api.audience_id grant_types = ["authorization_code", "refresh_token"] token_endpoint_auth_method = "client_secret_basic" post_logout_redirect_uris = ["https://app.example.com/"] config = data.authwise_interactive_client_config.web.any}
resource "authwise_application_secret" "web" { application_id = authwise_application.web.application_id}
output "client_id" { value = authwise_application.web.application_id}
output "client_secret" { value = authwise_application_secret.web.secret sensitive = true}Both resources belong to an issuer. Set issuer_id in the provider
block, or on each resource; without it, Terraform reports missing required scope attribute "issuer_id". The application’s
application_id is the client_id your library sends.
Redirect URIs are matched exactly, scheme and path included. During
development, register http://localhost:PORT/callback alongside the
production URI.
Sign in: the authorization code flow with PKCE
Section titled “Sign in: the authorization code flow with PKCE”-
The application creates a random
code_verifier, derivescode_challengeas its SHA-256 hash in base64url, and stores the verifier with a randomstateandnonce. -
It sends the browser to the authorization endpoint:
ISSUER_URL/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https://app.example.com/callback&scope=openid profile email offline_access&state=STATE&nonce=NONCE&code_challenge=CHALLENGE&code_challenge_method=S256 -
The person signs in on the issuer’s hosted page. The issuer redirects back with
code,state, andissas query parameters. -
The application checks
state, then posts the code to the token endpoint with the verifier. A confidential client authenticates with its secret; a public client sends only itsclient_id:Terminal window curl -s ISSUER_URL/oauth/token \-u "CLIENT_ID:CLIENT_SECRET" \-d grant_type=authorization_code -d code=CODE \-d redirect_uri=https://app.example.com/callback \-d code_verifier=VERIFIER{"access_token": "eyJ…","id_token": "eyJ…","refresh_token": "…","token_type": "Bearer","expires_in": 900} -
The application validates the ID token’s signature against the JWKS, its
iss,aud(the client ID),exp, andnonce, and starts its own session.
Every library in the quickstarts does steps 1, 4, and 5 for you.
Scopes and claims
Section titled “Scopes and claims”| Scope | What it adds |
|---|---|
openid | Required. The ID token with sub. |
profile | name, given_name, family_name. |
email | email, email_verified. |
offline_access | A refresh token in the token response. |
The ID token carries these claims:
| Claim | Value |
|---|---|
sub | The person’s ID, such as u-g1yurrsfbldw. It is stable across sign-ins and never changes. Key your records on it, not on the email address. |
iss, aud, exp, iat, nonce, jti | Standard. aud is the client ID. |
auth_time | When the person last authenticated. |
acr, amr | How strong the sign-in was and how it was done, such as urn:authwise:acr:1 with ["pwd"]. Step-up and MFA raise acr. |
email, email_verified, name, given_name, family_name | With the matching scopes. name is the person’s display name; when none is set, it is the given name and family name joined with a space. |
The access token
Section titled “The access token”The access token is a signed JWT for the audience the client names. Send it as a bearer token to that API, and let the API validate it. It carries these claims:
| Claim | Value |
|---|---|
aud | The audience’s identifier, such as https://api.example.com. The API checks that it is its own. |
sub | The person’s ID, the same value as in the ID token. For a client_credentials token, the client’s ID. |
client_id | The client that obtained the token. |
iss, exp, iat, jti | Standard. |
auth_time, acr, amr | On a token a person’s sign-in produced, as in the ID token. |
roles, permissions, groups | When the audience’s configuration includes them. See Roles in the access token and Read roles and permissions from the token. |
The access token carries no profile or email claims, whatever scopes the
client asked for. name, email, and the other profile claims are in
the ID token and at the userinfo endpoint only. An API that shows who is
calling reads sub from the access token and resolves the person at the
userinfo endpoint with the same bearer:
curl -s ISSUER_URL/userinfo -H "Authorization: Bearer ACCESS_TOKEN"{"email":"ben.tomasini@authwise.com","email_verified":true,"family_name":"Admin","given_name":"Admin","name":"Admin","sub":"u-01"}Cache the answer per sub for the access token’s lifetime.
Roles in the access token
Section titled “Roles in the access token”An audience can put the roles a person holds for it in its access
tokens. In the console, open the audience and, under What its access
tokens carry, turn on The person’s roles. With Terraform, set
scopes = { authorization = { include_roles = true } } on
data.authwise_audience_config. The client doesn’t need to request a
scope: with the setting on, the audience’s access tokens carry the claim
for a person who holds roles there. A client may still send roles in
scope, and the issuer accepts it.
"roles": ["orders.viewer", "orders.approver"]Each value is the role’s name, the last part of its resource name, such
as orders.viewer for
tenants/TENANT_ID/issuers/ISSUER_ID/audiences/AUDIENCE_ID/access-roles/orders.viewer.
The name is what bindings and Terraform reference, and it doesn’t change
when someone edits the role’s display name. Match on it in your API.
The permissions claim works differently: it carries only the permissions
that the request asked for, and it’s empty when the request asked for
none. To define roles and permissions for your API, and for both ways to
ask for permissions, see
Authorize with Authwise Access and
Read roles and permissions from the token.
Keep the session alive
Section titled “Keep the session alive”Access tokens live for 900 seconds by default. The issuer, audience, and client can each set their own lifetime. Two mechanisms renew without a new sign-in.
Refresh tokens
Section titled “Refresh tokens”Ask for offline_access and the token response includes a refresh
token. Exchange it at the token endpoint:
curl -s ISSUER_URL/oauth/token \ -u "CLIENT_ID:CLIENT_SECRET" \ -d grant_type=refresh_token -d refresh_token=REFRESH_TOKENThe response carries a new access token, a new ID token, and a new refresh token. Refresh tokens rotate on every use, and a refresh token that was already used is refused:
{"error": "invalid_grant", "error_description": "refresh token already used"}Store the newest refresh token every time. By default a refresh token expires after 12 hours without use, and the idle window restarts on each rotation. Its family also has an absolute cap, 30 days by default, after which the person signs in again whatever the activity. An administrator sets both lifetimes at the tenant, issuer, audience, or client.
A server-side application keeps the refresh token on the server. A single-page application holds one in the browser, in memory or in the library’s session storage, never in a cookie the API reads. It is the renewal path for a single-page application, for the reason in the next section.
Silent renewal
Section titled “Silent renewal”A browser application can also renew through the issuer’s own session.
An authorization request with prompt=none is answered with a new code
while the person’s session at the issuer is alive, and no page is shown.
After the person signs out or the issuer session ends, the answer is an
error:
error=login_required&error_description=login+requiredHandle it by starting an interactive sign-in.
The request must carry the issuer’s session cookie, which is
SameSite=Lax. A top-level navigation carries it; a hidden iframe on
another site does not. So an application on its own origin cannot renew
through an iframe, and renews with the refresh token instead. Libraries
such as oidc-client-ts prefer the refresh token whenever
offline_access was granted, which is why the
React quickstart asks for it.
Call the issuer from a browser application
Section titled “Call the issuer from a browser application”A single-page application calls the token endpoint, the userinfo
endpoint, and the revocation endpoint from its own origin, so the browser
applies CORS. The issuer answers a token or revocation request with
Access-Control-Allow-Origin only for an origin you allowed. Without
it, the browser blocks the response and the library reports a network or
CORS error, although the issuer answered.
Allow the application’s origin, scheme and port included, such as
https://app.example.com or http://localhost:5173. You can allow it
on the tenant, the issuer, the audience, or the client:
-
On the issuer, for every client of that issuer: in the console, open the issuer, go to the Settings tab, and under Advanced open Browsers that may call it.
-
On the audience, for every client that calls that API: in the console, open the audience and add the origin under Browsers that may call it.
-
On the client, for that application alone: set
corsin the client’s configuration. The console has no field for it. With Terraform:data "authwise_interactive_client_config" "spa" {allowed_redirect_uris = ["https://app.example.com/callback"]cors = jsonencode({ allowedOrigins = ["https://app.example.com"] })}With
awctl, pass the client’s whole configuration with thecorsblock added.--configreplaces the configuration; it doesn’t merge, so repeat the redirect URIs:Terminal window awctl identity applications update CLIENT_ID --tenant-id TENANT_ID --issuer-id ISSUER_ID \--config '{"@type":"type.googleapis.com/authwise.types.core.v1alpha1.InteractiveClientConfig","allowed_redirect_uris":["https://app.example.com/callback","https://app.example.com/silent-renew.html"],"cors":{"allowed_origins":["https://app.example.com"]}}'Updated tenants/t-g3wq78hbfjls/issuers/i-g50tkucfpjxv/applications/c-g50tmbajq3ps
An origin on the client applies to requests that name the client, which the token request does in its body.
The browser sends a preflight OPTIONS request first when the token
request carries a header outside the CORS safelist, such as
Authorization. A preflight has no body, so it
can’t name the client. From identity server 1.98.0, the preflights of
/oauth/token and /oauth/revoke answer Access-Control-Allow-Origin: * without credentials, as /userinfo does, and allow the headers
Accept, Accept-Language, Content-Language, Origin,
Authorization, and Content-Type. The POST response itself still
allows only the origins you listed, and neither endpoint reads a cookie.
Before 1.98.0, the preflight allowed only an origin listed on the tenant
or the issuer, so an origin listed only on the client failed there; list
it on the issuer on those versions.
Sign out
Section titled “Sign out”Send the browser to the end-session endpoint with the ID token and a registered post-logout redirect URI:
ISSUER_URL/logout?id_token_hint=ID_TOKEN&post_logout_redirect_uri=https://app.example.com/&state=STATEThe issuer ends its session and redirects back with the same state.
Clear your own session before you redirect. A later prompt=none request
then fails with login_required, so other tabs of the same application
learn about the sign-out at their next renewal.
Framework quickstarts
Section titled “Framework quickstarts”Each page is one screen: install, configuration, the callback, a protected page, and sign-out, with a library that implements this page.
| Stack | Library | Quickstart |
|---|---|---|
| Next.js | Auth.js | Next.js |
| React single-page application | oidc-client-ts | React SPA |
| Vue single-page application | oidc-client-ts | Vue SPA |
| Node.js with Express | openid-client | Node.js |
| Go | go-oidc with golang.org/x/oauth2 | Go |
| Python with FastAPI | Authlib | Python |
Any certified OpenID Connect library works the same way. Give it the issuer URL, the client ID, the secret if the client has one, the redirect URI, and the scopes.