Skip to content

SAML NameID format reference

Every NameID format in SAML 2.0, what each carries, when to use it, and which Keycloak setting sends it.

Runs in your browser. Nothing you paste is sent to us.

Persistent

Format
urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
Carries
An opaque id that stays the same for this user at this service provider, and differs between service providers. At most 256 characters.
Use it for
Accounts that must survive changes to the username or email, without telling each app who the user is elsewhere.
Keycloak
Name ID format: persistent

Transient

Format
urn:oasis:names:tc:SAML:2.0:nameid-format:transient
Carries
An opaque id that is valid for this session only and changes every time.
Use it for
Apps that need no stable account, or that identify the user by attributes instead.
Keycloak
Name ID format: transient

Email address

Format
urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
Carries
An email address (an addr-spec as in RFC 2822).
Use it for
Apps that key accounts by email. The id changes when the email does.
Keycloak
Name ID format: email

Unspecified

Format
urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
Carries
Anything; the meaning is agreed between the two sides.
Use it for
Usernames and other ids that fit no other format. The most common choice for legacy apps.
Keycloak
Name ID format: username

X.509 subject name

Format
urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName
Carries
A certificate subject in the form of ds:X509SubjectName, such as CN=Alice,O=Example.
Use it for
Setups where users are identified by their client certificate.
Keycloak
Not a choice in the client’s Name ID format setting

Windows domain qualified name

Format
urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName
Carries
A Windows account as DomainName\UserName, or UserName alone.
Use it for
Apps that look users up in Active Directory by their logon name.
Keycloak
Not a choice in the client’s Name ID format setting

Kerberos principal

Format
urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos
Carries
A Kerberos principal name, name[/instance]@REALM.
Use it for
Apps tied to a Kerberos realm.
Keycloak
Not a choice in the client’s Name ID format setting

Entity

Format
urn:oasis:names:tc:SAML:2.0:nameid-format:entity
Carries
The entity id of a SAML provider, not a user.
Use it for
The Issuer element of messages and assertions. It is the default format of Issuer.
Keycloak
Not a choice in the client’s Name ID format setting

Encrypted

Format
urn:oasis:names:tc:SAML:2.0:nameid-format:encrypted
Carries
Not a format of its own: it asks for the NameID to arrive encrypted (EncryptedID).
Use it for
Only in the Format of an AuthnRequest’s NameIDPolicy.
Keycloak
Not a choice in the client’s Name ID format setting

How to use it

  1. Find the format your app asks for or expects.
  2. Read what the value looks like and whether it stays the same between sign-ins.
  3. Copy the full URN for metadata, requests or configuration.

What to know

The NameID is the user’s identifier in the assertion’s Subject. Its Format attribute says how to read it: an email address, a username, or an opaque id that is persistent or changes every time.

A Keycloak SAML client has a Name ID format setting with four choices: username, email, transient and persistent. Username is sent with the unspecified format. Unless Force name ID format is on, Keycloak uses the format the app asks for in its request.

Pick a format that does not change for the user. Email addresses change; a persistent id does not.

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.

A NameID in an assertion (sample)
<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

FormatValue looks likeStable across sign-ins
persistentOpaque id, unique per appYes
transientOpaque id, new each timeNo
emailAddressAn email addressUntil the address changes
unspecifiedAnything agreed, often a usernameDepends
X509SubjectNameA certificate subject such as CN=…Until the certificate changes
WindowsDomainQualifiedNameDOMAIN\userUntil the account is renamed
kerberosname@REALMUntil the principal changes
entityAn entity id of a SAML partyNot 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 settingFormat sentValue
username…:1.1:nameid-format:unspecifiedThe Keycloak username
email…:1.1:nameid-format:emailAddressThe user’s email
persistent…:2.0:nameid-format:persistentAn opaque id Keycloak keeps for the user and client
transient…:2.0:nameid-format:transientA 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

  1. Read the app’s documentation. If it names a format, use that one.
  2. If the app keeps accounts and you choose freely, prefer persistent.
  3. If the app keys accounts by email, emailAddress works, but plan for email changes.
  4. If the app needs no account, use transient.
  5. Use unspecified for usernames and legacy apps that expect a plain login name.

Common problems

  • InvalidNameIDPolicy in 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:

  1. Find out what the app matches on: the NameID value only, or also an attribute such as email.
  2. 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.
  3. Change the format at the identity provider and in the app’s expected format at the same time, in a quiet period.
  4. Sign in with a test user, read the assertion with the SAML response decoder, and check that the account found is the old one.
  5. 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.

Questions

Frequently asked questions

What is the difference between persistent and transient NameID?

A persistent NameID stays the same for a user at one app across sign-ins. A transient NameID changes every time, so the app cannot recognize a returning user by it.

What does urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified mean?

The format is left to agreement between the two sides. It is often used for usernames. Keycloak sends it when a client’s Name ID format is username.

Which NameID format should I use?

The one the app documents. If you choose freely and the app keeps accounts, persistent is the most stable and private choice.

What causes InvalidNameIDPolicy?

The app asked, in its AuthnRequest, for a NameID format the identity provider will not issue for it. Change the requested format or allow it at the identity provider.

What is Force name ID format in Keycloak?

A SAML client setting. When on, Keycloak ignores the format the app requests and always sends the format set on the client.

Is the emailAddress NameID format a good idea?

It is simple and common, but email addresses change and can be reassigned. If the app keys accounts on it, an address change can create a second account.

How long can a persistent NameID be?

SAML 2.0 core limits persistent identifiers to 256 characters.

Why are some formats SAML 1.1 and others SAML 2.0?

Formats that already existed in SAML 1.1 kept their old URNs. They are still valid SAML 2.0 formats.

What are NameQualifier and SPNameQualifier?

Optional attributes on a NameID. NameQualifier names the identity provider that issued the identifier, and SPNameQualifier the app it was issued for. They matter most for persistent identifiers, which are only meaningful for that pair.

What is an EncryptedID?

A NameID encrypted for the app, so that systems in between cannot read it. An app asks for one with the encrypted format in its NameIDPolicy, and only the app’s private key can read it.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.