Single Sign-On: Acronyms Demystified
Even if you understand the significance of adding SSO to your application, you may still feel overwhelmed by the different authentication-related acronyms and protocols. Nevertheless, after reading this post, we hope that you will have a better understanding of the distinctions between SAML, OIDC, and OAuth and feel more confident in implementing SSO in your application.
If you have gone through our Developer’s Guide to SSO, you should have some knowledge of what Single Sign-On is. In case you haven't read it yet, we highly recommend it as it serves as a great starting point. Essentially, SSO allows a user to utilize one set of login credentials to access multiple applications. This translates to a smoother experience, better security, and higher retention rates.
Even if you understand the significance of adding SSO to your application, you may still feel overwhelmed by the different authentication-related acronyms and protocols, which have numerous specifications that can take years to comprehend. Nevertheless, after reading this post, we hope that you will have a better understanding of the distinctions between SAML, OIDC, and OAuth and feel more confident in implementing SSO in your application.
OAuth 2.0 (Open Authorization)
OAuth is an open access delegation framework that uses HTTPS to authorize devices, APIs, servers, and applications with access tokens. Essentially, OAuth enables users to authorize one application to interact with another without requiring them to share their passwords.
OAuth has become nearly universal. Since the 2.0 specification was introduced over a decade ago, most modern internet users have been using OAuth without even realizing it.
To demonstrate, let's examine some options Spotify offers for authentication beyond basic email and password.
If you choose to use Facebook as your authentication, you'll see a prompt for access delegation that displays the following:
OAuth is a framework that allows users to grant applications access to resources without the need to share their passwords. In an OAuth flow, there are four primary actors involved:
- The Resource Owner: owns the data in the resource server
- The Resource Server: the API that stores the data we want to access
- The Client: the application that wants access
- The Authorization Server: OAuth’s main engine
As developers, it's important to understand the grant types available and choose the one that's most appropriate for the application.
One of the grant types that we'll explore in more detail here is the Authorization Code grant type. With this grant type, the user is redirected to the authorization server to grant access to the application. Once authorized, the authorization server sends an authorization code back to the application, which can then be exchanged for an access token.
It's important to note that OAuth is not an authentication protocol. While OAuth can be used to build an authentication protocol and is the backbone of the OpenID Connect (OIDC) standard, it is primarily an authorization framework. The access token returned by OAuth lacks an authentication component and is scoped to the permissions that the user has granted (RFC 6749).
While OAuth is closely related to authentication, treating it as an authentication protocol can have security implications. OAuth should only be used for authorization purposes, and any authentication should be handled through a separate protocol. When a user grants authorization to an application, it doesn’t usually expire. Because of this, it can be hard to verify if a user is really there, which authentication protocols require.
Takeaways and Further Reading:
- Because OAuth is an authorization framework it doesn’t verify the identity of a user (more about authentication vs authorization here)
- On success, applications are granted access token from an authorization server allowing access through means other than basic authorization
- Scopes provide a way to limit the amount of access granted in an access token (more about OAuth Scopes here)
OIDC (OpenID Connect)
OIDC is an authentication layer built on top of the OAuth 2.0 framework that returns the user’s identity as a JSON Web Token (JWT) called an ID Token. The primary actors in OIDC are:
- The End User: the entity for which we request identity information (this is equivalent to the RO in OAuth)
- Relying Party (RP): client that relies on the IDP in order to authenticate users and request claims
- OpenID Provider (OP): authorization server that offers authentication as a service.
These actors can engage in one of three supported flows:
- Authorization Code Flow: used by clients that can securely maintain a Client Secret between themselves and the Authorization Server. The Authorization Code Flow with Proof Key for Code Exchange (PKCE) is a popular choice, because of its ability to prevent authorization code injection.
- Implicit Flow: intended for clients that can not keep this secret. No longer recommended.
- Hybrid Flow: enables clients to obtain some tokens straight from the Authorization Endpoint, while still having the possibility to get others from the Token Endpoint.
Here is what an Authorization Code Flow with PKCE looks like:
PKCE introduces the concepts of code_verifier and code_challenge to the OIDC flow. The client creates and records a secret named called the “code_verifier”, and derives a transformed version “t(code_verifier)” (referred to as the “code_challenge”), which is sent in the OAuth 2.0 Authorization Request along with the transformation method “t_m”. This prevents Authorization Code Interception Attacks, particularly in mobile apps.
The ID Token we receive in step 5 will look a little something like this when it arrives:
The JWT is sent as a Base 64 encoded string, and can be decoded to reveal a JSON-formatted header, payload, and signature.
Here is an example of what the body containing a user’s claims might look like after decoding:
Before creating a session for our user in our application we will need to verify:
- the signature used to sign the ID token
- the claims found in the ID token
The OIDC authentication process is simpler than the SAML verification process, which contributes to its popularity among developers. Upon successful validation of a user, their session can be created.
Takeaways and Further Reading:
- An authentication protocol built on top of the OAuth 2.0 Framework
- Returns a user’s identity in a JWT called an ID Token
- An application can use an authorization code flow, implicit flow, or hybrid flow with OIDC (view diagrams of all the OpenID flows here)
- Many developers find OIDC is easier to implement securely due to the relative ease of working with JSON (more about why a business may choose OIDC)
SAML (Security Assertion Markup Language)
SAML is an authentication protocol widely employed by enterprises to enable federated authentication. In this scenario, a user has a single digital identity managed by an identity provider (IdP). The IdP establishes trust with other applications, allowing a user to sign in to multiple applications without separate passwords.
After the IdP establishes the user's identity, it returns an XML document called a SAML assertion containing the user's claims to the service provider (SP). The SP then uses this assertion to create a session for the user.
SAML is mostly utilized in enterprise environments, and it is probable that you have encountered it in the workplace. A well-known example is Okta:
In SAML there are three primary actors:
- User Agent: typically a web browser
- Service Provider (SP): the one issuing an authentication request, typically the application a user is logging into
- Identity Provider (IdP): the party providing authentication information for the user, in our example, Okta
These three actors come together to shape the SAML flow, which varies depending on whether the request is:
- IdP Initiated: a user logging in from the identity provider, such as by clicking the 1Password tile in Okta
- SP Initiated a user logging in from the application, such as by going to 1Password directly
Both are illustrated in the following flow:
Here is an example of a successful SAML response from Azure:
The XML format may pose challenges for quick human parsing, but even a cursory glance reveals the assertion that contains user attributes such as name, first name, last name, and email. These attributes can be utilized by the service provider (SP) to create sessions for the user.
However, the receipt of an assertion with claims alone does not suffice to create a session. The validity of the assertion must also be verified by the application per the SAML specification, by validating the response signature. However, even with this validation, the application remains vulnerable to security threats. In the event that an assertion is deemed invalid at any point in the process, a session should not be created for the user.
Once the validity of an assertion is confirmed, the attributes in the response can be employed to create a session.
Takeaways and Further Reading:
- SAML authentication can be either IdP or SP initiated (more in the WorkOS documentation here)
- A successful response will return a user’s identity in the form of an XML document called the SAML assertion
- SAML is well established and feature rich, so it’s a popular choice with businesses.
- It is relatively easy to accidentally introduce security vulnerabilities in SAML implementations.
After reading this post, you should have a greater understanding of the technical differences between SAML, OIDC, and OAuth. However, if the prospect of managing these diverse flows, protocols, and identity providers still seems overwhelming, there are third-party vendors available who specialize in offering a secure, efficient, and user-friendly approach to implementing SSO. WorkOS simplifies many of the complexities discussed in this post and seamlessly delivers a standardized profile object to your application upon successful authentication.
The decision to build or buy can be challenging for any organization. However, if you find the idea of implementing a centralized SSO API to streamline authentication appealing, WorkOS's Single Sign-On product may be the perfect fit for your needs. To explore how WorkOS can simplify your authentication process and experience the benefits firsthand, don't hesitate to get in touch with our team today.