What a NameID is
Every SAML assertion is about someone, the subject. The NameID inside saml:Subject is the identifier the identity provider gives the app for that user. The app uses it to find the user’s account, and both sides use it again for logout.
The Format attribute says what kind of identifier it is: an email address, an opaque id, a username, and so on. SAML 2.0 core, section 8.3, defines the standard formats. Apps and identity providers must agree on one, or sign-in fails or lands in the wrong account.
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
NameQualifier="https://auth.example.com/realms/acme"
SPNameQualifier="https://app.example.com/saml/metadata">G-5c1e0a7e…</saml:NameID>
</saml:Subject>The standard formats at a glance
| Format | Value looks like | Stable across sign-ins |
|---|---|---|
| persistent | Opaque id, unique per app | Yes |
| transient | Opaque id, new each time | No |
| emailAddress | An email address | Until the address changes |
| unspecified | Anything agreed, often a username | Depends |
| X509SubjectName | A certificate subject such as CN=… | Until the certificate changes |
| WindowsDomainQualifiedName | DOMAIN\user | Until the account is renamed |
| kerberos | name@REALM | Until the principal changes |
| entity | An entity id of a SAML party | Not used for users |
Formats that existed in SAML 1.1 kept their urn:oasis:names:tc:SAML:1.1:nameid-format: names in SAML 2.0. The formats new in 2.0 use urn:oasis:names:tc:SAML:2.0:nameid-format:. Both are valid in SAML 2.0 messages.
Persistent and transient in detail
Persistent
A persistent identifier is an opaque value that stays the same for one user at one app, and differs between apps. It reveals nothing about the user, and two apps cannot use it to tell they share a user. The core spec limits it to 256 characters.
It is the best choice when the app keeps accounts and you do not want the account tied to a username or email that may change. The NameQualifier and SPNameQualifier attributes record which identity provider and app the value belongs to.
Transient
A transient identifier is a random value valid only for the current session. The app cannot recognize a returning user by it. It suits apps that do not keep accounts, or that identify users by attributes such as an employee number instead.
How the app asks for a format
The app can name a format in two places: in its metadata as NameIDFormat elements, and in each AuthnRequest as NameIDPolicy Format. The identity provider then sends that format or refuses with the status InvalidNameIDPolicy.
The value urn:oasis:names:tc:SAML:2.0:nameid-format:encrypted is special. It is not a format of its own; it asks for the identifier to arrive encrypted, as an EncryptedID. It may appear only in NameIDPolicy.
NameID formats in Keycloak
A Keycloak SAML client has a Name ID format setting with four choices. Each sends one of the standard formats:
| Keycloak setting | Format sent | Value |
|---|---|---|
| username | …:1.1:nameid-format:unspecified | The Keycloak username |
…:1.1:nameid-format:emailAddress | The user’s email | |
| persistent | …:2.0:nameid-format:persistent | An opaque id Keycloak keeps for the user and client |
| transient | …:2.0:nameid-format:transient | A new opaque id each time |
With Force name ID format off, Keycloak uses the format the app asks for in its request; when the request names none, it uses the client setting. With it on, Keycloak always sends the client setting and ignores the request. Turn it on when an app asks for one format but really needs another.
Keycloak as the app
When Keycloak brokers sign-in through another SAML identity provider, the identity provider’s settings include a NameID policy format, which Keycloak puts in its requests, and a Principal type, which decides whether Keycloak identifies the external user by the NameID or by an attribute.
What this reference does
The tool above lists every format from SAML 2.0 core with its full URN, what the value carries, when to use it, and the matching Keycloak setting where there is one. Filter by any word, and copy a URN with one click for metadata, requests or configuration.
Choosing a format
- Read the app’s documentation. If it names a format, use that one.
- If the app keeps accounts and you choose freely, prefer persistent.
- If the app keys accounts by email, emailAddress works, but plan for email changes.
- If the app needs no account, use transient.
- Use unspecified for usernames and legacy apps that expect a plain login name.
Common problems
InvalidNameIDPolicyin the response: the app asked for a format the identity provider does not allow for it. Change the request or allow the format.- Users get new, empty accounts after a change: the format or its value source changed, for example from email to persistent.
- Duplicate accounts after an email change: the app keys accounts on an emailAddress NameID.
- The app rejects a persistent value: it expected a username or email and treats the opaque id as unknown.
- Logout fails: the app sends a NameID in a different format than the one in the assertion.
- The NameID is empty or sign-in fails at the identity provider: the user has no value for the chosen format, for example no email address with the email format.
Privacy and security
Email addresses and usernames tie a user’s activity across apps. Persistent and transient identifiers are designed not to. When an app does not need to know who the user is in other systems, an opaque identifier plus only the attributes it needs is the more private setup.
Whatever the format, the NameID is only trustworthy inside a signed assertion that passed every check.
In Keycloak, a persistent identifier is kept per client, so two SAML clients in the same realm get different values for the same user. That is the intended behavior. If two apps must agree on who a user is, send them a shared, stable attribute such as an employee number, not the persistent NameID.
Changing the format of a live app
Apps link a NameID value to an account. If you change the format, every user arrives with a new value, and an app that matches only on NameID will create new, empty accounts or refuse the users. Plan the change:
- Find out what the app matches on: the NameID value only, or also an attribute such as email.
- If the app supports it, send a stable attribute it can match on during the move, such as the user’s email or an employee id.
- Change the format at the identity provider and in the app’s expected format at the same time, in a quiet period.
- Sign in with a test user, read the assertion with the SAML response decoder, and check that the account found is the old one.
- Watch for duplicate accounts in the first days and merge them.
NameID and single logout
Logout reuses the NameID. A LogoutRequest must carry the same NameID, with the same format and qualifiers, that the assertion carried, plus the session index. If the app stores only the value and sends it back without the format, or with another one, the identity provider may not find the session and the logout fails silently.
Transient identifiers make this matter even more: the value exists only for that session, so the app must keep it exactly as received until the user logs out.