Skip to content

Sign in with Protokol (OpenID Connect)

Let users sign in to your app with their Protokol account. Protokol implements OpenID Connect Core 1.0 on top of the OAuth authorization code flow with PKCE: your app receives an id_token that says who the user is, and can read their name and email from the userinfo endpoint.

Read the OAuth guide first. Registering a client, PKCE, redirect handling, token exchange and error handling are the same here. This page covers only what OpenID Connect adds.


When to use it

You want to... Use
Know who the user is and keep them signed in to your own app Sign in with Protokol: request openid
Call the Protokol API on the user's behalf Plain OAuth with permission scopes
Both Request openid together with the permission scopes

Note

Sign in is for user connections only. A client with the Project installation access type acts for a project, not a person, so a request containing openid fails with invalid_scope.

Only the authorization code flow is supported, with response_type=code and PKCE S256. There is no implicit or hybrid flow.


Discovery

The OpenID Connect discovery document is public. Most libraries only need this URL:

curl https://lemon.protokol.io/.well-known/openid-configuration
{
  "issuer": "https://lemon.protokol.io",
  "authorization_endpoint": "https://lemon.protokol.io/v1/oauth/authorize",
  "token_endpoint": "https://lemon.protokol.io/v1/oauth/token",
  "userinfo_endpoint": "https://lemon.protokol.io/v1/oauth/userinfo",
  "jwks_uri": "https://lemon.protokol.io/.well-known/jwks.json",
  "revocation_endpoint": "https://lemon.protokol.io/v1/oauth/revoke",
  "introspection_endpoint": "https://lemon.protokol.io/v1/oauth/introspect",
  "response_types_supported": ["code"],
  "grant_types_supported": ["authorization_code", "refresh_token"],
  "subject_types_supported": ["public"],
  "id_token_signing_alg_values_supported": ["RS256"],
  "scopes_supported": ["openid", "profile", "email", "offline_access"],
  "claims_supported": ["sub", "iss", "aud", "azp", "exp", "iat", "auth_time", "nonce", "at_hash", "name", "email", "email_verified"],
  "code_challenge_methods_supported": ["S256"]
}

The signing keys are published at https://lemon.protokol.io/.well-known/jwks.json. The OAuth server metadata at /.well-known/oauth-authorization-server is still available. Read the endpoint URLs and the issuer from the document instead of hard-coding them.


Scopes

openid, profile and email are plain tokens, like offline_access. They are not permissions and are not encoded with perm64:.

Scope Required Gives you
openid yes An id_token in the token response, and access to userinfo
profile no name from userinfo
email no email and email_verified from userinfo

Example scope value:

openid profile email offline_access

On the consent screen openid appears as "Sign you in to your app" and cannot be unticked. The user can untick profile and email ("Your name", "Your email address"). Your app then receives a token without them, and userinfo leaves those claims out. Never assume you got them: read the scope in the token response and treat name and email as optional.


Sign-in-only apps

An app that only needs to know who the user is does not need any API permission. Request just openid profile email (or a subset). The consent screen then shows only the sign-in lines, and the access token can call userinfo and nothing else.

To list a sign-in app in the marketplace, see Web apps.


Authorize request

Add openid to scope and, optionally, the parameters below. Everything else is as in Send the user to authorize.

project_id is optional. If you omit it, Protokol asks the user to choose a project when needed; see Choosing the project. For a sign-in button you will usually leave it out and read project_id from the token response.

GET https://lemon.protokol.io/v1/oauth/authorize
  ?response_type=code
  &client_id=pk_cli_0123456789abcdef0123456789abcdef
  &redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
  &project_id=YOUR_PROJECT_ID
  &state=STATE
  &nonce=NONCE
  &code_challenge=CHALLENGE
  &code_challenge_method=S256
  &scope=openid%20profile%20email
Parameter Notes
nonce Recommended. A random string of at most 255 bytes, generated per login and stored in the user's session. Protokol returns it unchanged in the id_token, and your app must check that it matches. This stops a stolen id_token from being replayed into another login
prompt none, login, consent or select_account. Values can be combined with a space, except that none cannot be combined with anything else (invalid_request)
max_age A non-negative number of seconds. If the user last signed in longer ago than this, they must sign in again. The id_token then always contains auth_time

prompt values:

Value Behaviour
none Never shows any screen. If the user is signed in and has already approved the requested access, you get a code straight away. Use it for silent re-authentication
login Forces the user to sign in again even if they have a session
consent Forces the consent screen even if the user approved before
select_account Always asks the user to choose a project, even if only one project qualifies or the user already connected your app in one of them. Only meaningful when you did not send a project_id

With prompt=none the result comes back as an error redirect (with your state and iss) when it cannot be done silently:

error Meaning What to do
login_required There is no signed-in user, or max_age has been exceeded Send the user through again without prompt=none
consent_required The user has not yet approved the requested scopes Send the user through again without prompt=none
account_selection_required You sent no project_id, and the user can choose between several projects and has not connected your app in one of them Send the user through again without prompt=none so they can choose a project
interaction_required Your app is not yet installed in the project and an admin must install it, or the user must act on the consent screen Send the user through again without prompt=none. See Installing the app in a project

request, request_uri and registration are not supported and fail with request_not_supported, request_uri_not_supported and registration_not_supported. login_hint and claims are ignored.


Token response

When the granted scopes include openid, the token response contains an id_token next to the access token:

{
  "access_token": "eyJ…",
  "token_type": "Bearer",
  "expires_in": 900,
  "id_token": "eyJ…",
  "scope": "openid profile email",
  "project_id": "YOUR_PROJECT_ID"
}

project_id is the project the token is bound to. It is how your app learns which project the user chose when you did not send one.

The id_token is a JWT signed with RS256. It is valid for 5 minutes: validate it when you receive it and then create your own session. Do not use it as an API credential.

Claim Value
iss The issuer from the discovery document
sub The user's identifier. See Account linking
aud [your client_id]
azp Your client_id
iat, exp Issued-at and expiry (exp is iat + 300 seconds)
auth_time When the user signed in to Protokol
nonce The value you sent, if you sent one
at_hash Left half of the SHA-256 hash of the access token, base64url encoded

The id_token carries no name or email. Get them from userinfo.


Validate the id_token

Do not trust an id_token until every check below passes. If any check fails, reject the login.

Use a certified library

Use an OpenID Certified client library for your language instead of writing these checks yourself. It does all of them, handles JWKS caching and key rotation, and is much harder to get wrong.

Checklist

  1. Split the JWT and read the header. The alg must be RS256. Reject anything else, including none and HS256. Never let the token choose the algorithm you verify with.
  2. Fetch the JWKS from jwks_uri and select the key whose kid matches the header. If the kid is unknown, refetch the JWKS once (keys rotate) and then reject the token if it is still unknown.
  3. Verify the signature with that RSA public key.
  4. iss equals the issuer from the discovery document, exactly.
  5. aud contains your client_id. If aud has more than one value, azp must equal your client_id. Protokol always sets azp, so reject a token where it is present and different.
  6. exp is in the future and iat is not in the future. Allow a small clock skew of a minute or so.
  7. nonce equals the value you stored for this login. Reject the token if you sent a nonce and it is missing or different.
  8. at_hash equals the base64url encoding of the left half of the SHA-256 of the access_token from the same response.
  9. If you sent max_age, auth_time is present and now - auth_time <= max_age.

The JWKS response is cacheable for 5 minutes (Cache-Control: public, max-age=300). After a key rotation the old key stays published for at least 24 hours, so tokens signed before the rotation still verify.

Example with Node.js

This uses openid-client (v6), which performs the discovery, state, nonce, PKCE, signature, iss, aud, exp and at_hash checks for you.

import * as client from "openid-client"

const config = await client.discovery(
  new URL("https://lemon.protokol.io"),
  "pk_cli_0123456789abcdef0123456789abcdef",
  undefined,            // public client: no secret. Confidential client: pass the secret here
)

// 1. Start the login
const codeVerifier = client.randomPKCECodeVerifier()
const state = client.randomState()
const nonce = client.randomNonce()

const url = client.buildAuthorizationUrl(config, {
  redirect_uri: "https://app.example.com/callback",
  project_id: "YOUR_PROJECT_ID",
  scope: "openid profile email",
  code_challenge: await client.calculatePKCECodeChallenge(codeVerifier),
  code_challenge_method: "S256",
  state,
  nonce,
})
// store codeVerifier, state and nonce in the user's session, then redirect to url

// 2. On the callback
const tokens = await client.authorizationCodeGrant(
  config,
  new URL(request.url),                // the full callback URL
  { pkceCodeVerifier: codeVerifier, expectedState: state, expectedNonce: nonce, idTokenExpected: true },
)

const claims = tokens.claims()          // validated id_token claims
const sub = claims.sub

// 3. Name and email come from userinfo
const info = await client.fetchUserInfo(config, tokens.access_token, sub)

fetchUserInfo checks that the sub in the response matches the one you pass. Also compare the iss query parameter on the callback with the issuer, as described in Handle the redirect.


Userinfo

Send the access token to the userinfo endpoint. GET and POST both work.

curl https://lemon.protokol.io/v1/oauth/userinfo \
  -H "Authorization: Bearer ACCESS_TOKEN"
{
  "sub": "5f0c0c3e-0a52-4d6e-8d2b-1f6f8f0a9b11",
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "email_verified": true
}
Claim Returned when
sub Always
name The user granted profile
email, email_verified The user granted email

The response is sent with Cache-Control: no-store. Errors follow RFC 6750 in the WWW-Authenticate header: invalid_token for an expired or revoked token, and insufficient_scope when the token was not issued with openid.


Account linking

Identify users in your own database by sub, together with the issuer.

  • sub is stable: it never changes for a user, and it is the same value every time the user signs in to your app.
  • sub is the same for a user across all apps. It also matches the sub returned by token introspection.
  • Never use email as a key. Emails can change, and the user can decline to share it. Store email and name as profile data only, refresh them from userinfo when you need them, and use email_verified before you trust an address for anything else (such as sending mail).

Refresh

If you requested offline_access, refreshing a session that includes openid also returns a new id_token. It has the same sub, aud and auth_time as the original and no nonce, so do not require one when you validate it. All the other checks still apply. Name and email are still only available from userinfo.


Checklist

  • Request openid, and add profile and email only if you need them. Handle users who untick them.
  • Send a fresh nonce per login and check it in the id_token.
  • Accept RS256 only, and select the key by kid from the JWKS.
  • Check iss, aud/azp, exp, nonce and at_hash.
  • Key your users on sub, never on email.
  • Use an OpenID-certified library where you can.
  • Use a user-connection client. Project installations cannot request openid.