Certificates prove what a machine is. These standards prove who a person is, and pass that proof between systems.
Authentication vs authorization
- Authentication (AuthN): who are you?
- Authorization (AuthZ): what may you do?
Think of an office building. At the front desk a guard checks your photo ID and gives you a badge: that is authentication. The badge then opens some doors and not others, depending on your job: that is authorization. Being who you say you are does not mean you may enter the server room.
SSO products (the IdP) answer the first question; roles, groups and policies in each application answer the second. Mixing them up is a classic mistake: “the user logged in through SSO, so they must be allowed to do this” is a security hole, because login only proves identity.
JWT: a signed set of claims
A JSON Web Token (JWT, pronounced “jot”) is a small, signed message that
carries claims (statements) about a user, such as “this is alice, issued by
this IdP, valid until this time”. An application that trusts the issuer can
read the claims and act on them without calling the IdP again for every
request. It has three base64url parts separated by dots:
header.payload.signature:
- the header says how it was signed (
alg) and with which key (kid); - the payload holds the claims;
- the signature covers the first two parts, so none of them can be changed without detection.
(base64url is base64 with - and _ instead of + and / and no =
padding, so the token is safe to put in a URL or HTTP header. It is an
encoding, not encryption.)
Build one by hand to see there is no magic:
$ b64u() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
$ H=$(printf '{"alg":"ES256","typ":"JWT","kid":"k1"}' | b64u)
$ P=$(printf '{"iss":"https://idp.example.com","sub":"alice","aud":"bastionxp","exp":1893456000}' | b64u)
$ echo "$H.$P"
eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImsxIn0.eyJpc3MiOiJodHRwczovL2lkcC5leGFtcGxlLmNvbSIsInN1YiI6ImFsaWNlIiwiYXVkIjoiYmFzdGlvbnhwIiwiZXhwIjoxODkzNDU2MDAwfQ
The b64u helper turns text into base64url, and exp is a Unix timestamp
(seconds since 1 January 1970) saying when the token expires. Decoding the
first two parts is just base64:
{"alg":"ES256","typ":"JWT","kid":"k1"}
{"iss":"https://idp.example.com","sub":"alice","aud":"bastionxp","exp":1893456000}
The third part is the signature over header.payload, made with the
private key (openssl dgst -sha256 -sign ec.key). The receiver fetches the
IdP’s matching public key (see JWKS below), recomputes the signature check
over header.payload and accepts the token only if it verifies. One
JWT-specific detail: ECDSA signatures in a JWT are the raw 64 bytes r‖s,
not the DER form that OpenSSL writes, so tools must convert.
cut -d. -f2 | base64 -d
on it: the claims are right there. (A separate standard, JWE, encrypts the
payload, but you will rarely meet it.)Claims you must check
A valid signature only proves “the issuer made this token”. It does not prove the token is meant for you, or that it is still valid. Your code must check the claims too:
| Claim | Meaning | If you skip checking it |
|---|---|---|
iss | Who issued the token | Tokens from any IdP are accepted |
aud | Who the token is meant for | A token for app A works on app B |
exp / nbf | Expiry / not-before | Stolen tokens live forever |
sub | The subject: a stable, unique user ID. Use this, not the email, as the account key | Accounts get mixed up if the email changes |
nonce | Ties the token to the login request | Replay attacks |
JWT pitfalls
- Always pin the allowed algorithms. Never trust the token’s own
algheader, because the attacker writes the header. Two historic attacks:alg: none(the token claims it needs no signature, and a careless library agrees) and switching RS256 to HS256 (the attacker signs with HMAC, using the public key, which everyone knows, as the secret; a careless library then “verifies” it with that same public key). Your code should say “only ES256 is allowed” and ignore what the token claims. - Verify the signature before you read the claims. Anything in an unverified token is attacker-controlled input.
- Keep access tokens short (minutes) and use refresh tokens to get new ones. If an access token leaks, it is useful for only a few minutes.
- Allow only a small clock skew (a minute or two) when checking
expandnbf, because two computers’ clocks never agree exactly. A large allowance means expired tokens still work. - A JWT cannot be revoked once issued. Nothing “calls back” to cancel it, so a short life is the control.
JWK and JWKS: keys as JSON
How does an application get the IdP’s public key to check a signature? It
downloads it, in a format called JWK. A JSON Web Key is a public (or
private) key written as JSON. A JWKS (“JWK Set”) is a list of them,
usually published at a URL (the IdP’s jwks_uri) so anyone can verify its
tokens. The kid (“key ID”) in the token header says which key in the list
signed this token, which makes key rotation painless: publish the new key
next to the old one, start signing with the new key, and remove the old one
once all its tokens have expired. Apps normally cache the JWKS, which is why
“invalid token” errors often appear right after a rotation (the cache is
stale).
The P-256 public key from the basics page as a JWK
is its two curve coordinates, base64url-encoded (these are the real x and
y of ec.pub):
{
"kty": "EC",
"crv": "P-256",
"kid": "k1",
"use": "sig",
"alg": "ES256",
"x": "0gJZdxThB5nkot-XMAxj4DrHOYHrcPbWwIVaFyiau74",
"y": "EOdTTI-J5t2mOyLNYzDytGG3QgA8Sd3sqQdpEdfvg1U"
}
Compare with the 04:d2:02:59:77:... point printed by openssl pkey -text:
d2025977... base64url-encodes to 0gJZdxTh.... The 04 prefix is dropped,
and the remaining 64 bytes are split into x and y. Never publish the
d member: that is the private key.
In the JWK, kty is the key type, crv the curve, use says it is for
signatures (sig) rather than encryption (enc), and alg the algorithm.
Common kty values: RSA, EC, OKP (Ed25519/X25519), oct (symmetric).
OAuth 2.0 and OIDC
Start with the problem. A photo-printing site wants to read your pictures from a cloud storage account. In the old days you typed your storage password into the printing site, which could then do anything with your account, forever. OAuth 2.0 replaces that: you are sent to the storage provider, you log in there, you approve “let the printing site read my photos”, and the printing site receives a limited access token. It never sees your password, it gets only the permission you granted, and you can withdraw it later. OAuth 2.0 is about authorization.
OAuth alone does not tell the app who the user is, only that it may call some API. OpenID Connect (OIDC) adds authentication on top of OAuth 2.0. It adds the ID token: a JWT that says who logged in, and when, and how (for example “with MFA”), plus a standard way to look up the user’s name and email. “Log in with Google/Microsoft/Okta” buttons use OIDC.
| Term | Meaning |
|---|---|
| IdP / OP | The identity provider: Okta, Entra ID, Google Workspace, Keycloak |
| RP / client | The application that wants to know who you are |
| ID token | JWT about the login (who) |
| Access token | What the app presents to an API (what it may do) |
| Refresh token | Gets new access tokens without a new login |
| Scopes | What the app asks for: openid email profile groups |
| Redirect URI | Where the IdP sends the user back; must match exactly |
The login flow (authorization code + PKCE)
User/Browser App (client) IdP
| 1. click Login | |
|--------------------->| |
| 2. redirect to IdP, with client_id, scope, |
| state, nonce, code_challenge (PKCE) |
|<-----------------------------------------------|
| 3. user logs in, completes MFA |
|----------------------------------------------->|
| 4. redirect back with ?code=...&state=... |
|--------------------->| |
| | 5. POST code + |
| | code_verifier |
| |------------------------>|
| | 6. ID token + access |
| |<------------------------|
| | 7. verify signature |
| | against IdP's JWKS |
In words: the app never handles the password. It sends the user to the IdP (steps 1 and 2). The user proves who they are there, with whatever the IdP requires, such as MFA (step 3). The IdP sends the browser back to the app with a short-lived, one-time authorization code (step 4). The app then exchanges that code for the real tokens in a direct, back-channel request (steps 5 and 6), and verifies the ID token’s signature using the IdP’s JWKS (step 7).
Key points:
- The tokens are exchanged server to server (step 5), not through the browser URL. The code in the URL is useless on its own. If the tokens themselves were in the URL they would end up in browser history and logs.
stateis a random value the app invents in step 2 and checks in step 4. It blocks cross-site request forgery, where an attacker tricks a user’s browser into completing a login the attacker started.nonceis a random value that comes back inside the ID token, tying that token to this login request. It blocks token replay.- PKCE (pronounced “pixy”) stops a stolen
codefrom being redeemed by someone else: the app invents a secret (code_verifier), sends only its hash (code_challenge) in step 2, and reveals the secret in step 5. A thief who intercepts the code in step 4 does not know the secret. Use PKCE for every client, not just mobile apps. - Redirect URIs must match exactly. The IdP only sends the code to a pre-registered address, so a look-alike address cannot collect it.
- Discovery: every OIDC IdP publishes
https://<idp>/.well-known/openid-configuration, which lists its endpoints and itsjwks_uri, so you configure an app with a single URL.
SSO
Single Sign-On means you log in once to the IdP and get into many apps without another password. SSO is not a protocol itself. It is a user experience that is built with a protocol, either OIDC or SAML: each app trusts the IdP’s signed answer instead of keeping its own passwords.
Why security teams want it:
- One place for MFA and password policy, instead of every app doing it differently (or not at all).
- One place to disable a leaver. Turn off the IdP account and every connected app stops accepting new logins.
- One audit log of who logged in to what.
- Fewer passwords for users to reuse or write down.
The trade-off: the IdP becomes the most valuable target, so protect it with strong MFA (phishing-resistant if possible).
SAML 2.0
SAML (Security Assertion Markup Language) is the older, XML-based enterprise SSO protocol, from the early 2000s. It does the same job as OIDC, and you will meet it in older enterprise software and many SaaS admin consoles.
| OIDC | SAML 2.0 | |
|---|---|---|
| Format | JSON / JWT | XML assertion |
| Typical use | Modern web, mobile and APIs | Older enterprise apps |
| Signature | JWT signature | XML-DSig (finicky) |
| Trust setup | Discovery URL + client ID/secret | Exchange of metadata XML and certificates |
| Service name | RP / client | SP (service provider) |
SAML flow: the user visits the SP, the SP redirects to the IdP with an
AuthnRequest, the user logs in, and the IdP posts back a signed
assertion (name, attributes, groups, validity) that the SP verifies with
the IdP’s certificate. An assertion is SAML’s word for “the IdP
states that this user is alice, authenticated at this time, in these
groups”. The browser carries it from the IdP to the SP, which checks the XML
signature and the validity window before creating a session.
Note: SAML trust is really X.509. The SP is configured with the IdP’s signing certificate (usually by importing a metadata XML file), and trusts any assertion signed by it. When that certificate expires, logins stop everywhere at once, so it belongs on your expiry-monitoring list. When the IdP rotates it, every SP needs the new one.
SCIM: provisioning, the other half of SSO
SSO controls login. But what about the account itself? With SSO alone, an app creates a user record the first time someone logs in, and nobody tells it when that person leaves. SCIM (System for Cross-domain Identity Management) keeps the accounts and groups in sync automatically: the IdP creates, updates and removes users in the app when HR or the IdP changes. Without SCIM, a deleted IdP user can leave behind a live account (and any API keys that account created), which is a common audit finding.
How this ties to certificates
User certificates are a natural result of SSO:
- The user logs in to the IdP with OIDC (and MFA).
- The CA verifies the ID token (issuer, audience, expiry, signature via JWKS).
- The CA issues a short-lived X.509 or SSH certificate bound to that identity and its groups.
- The certificate is then used for mTLS or SSH without further passwords.
Why bother? Passwords and long-lived keys get stolen and shared. A certificate that lives for a few hours, issued only after a fresh SSO login with MFA, leaves very little for an attacker to steal, and when the user leaves the company they simply stop being able to log in to the IdP and nothing new can be issued.
That is the model behind SSO-driven certificate issuance, for example short-lived SSH certificates. The IdP proves who; the CA turns it into a credential for machines to check.
About BastionXP
BastionXP is a cloud-native private PKI CA and device identity management platform that eliminates passwords and shared secrets by issuing hardware-attested certificates to mobile devices and laptops. Secure access to your Wi-Fi, VPN, and SaaS applications in your enterprise network. Replace legacy SCEP with automated ACME Device Attestation. No shared secrets. Zero credential theft. Learn more about BastionXP →