Single sign-on, OAuth and tokens
Unit 5 of 5 in Identity and access.
You will be able to explain what OAuth 2.0 and OpenID Connect each do when you sign in with another account.
Lesson
The problem single sign-on solves
Without single sign-on every application keeps its own passwords, and every one is another place to get it wrong. With it, one trusted identity provider signs the user in, and other applications accept its answer. Fewer passwords exist, and one place enforces the strong sign-in from the last units.
OAuth 2.0 is about permission, not login
RFC 6749 describes the OAuth 2.0 authorization framework as enabling a third-party application to obtain limited access to an HTTP service, either on behalf of a resource owner through an approval interaction between the owner and the service, or on its own behalf. In plain words: an app can be allowed to do something specific for you without ever seeing your password.
The word that matters is limited. A token carries a narrow permission, called a scope, and for a limited time. That is least privilege applied to delegation.
OpenID Connect adds who you are
OAuth by itself says what an app may do, not who the user is. OpenID Connect is a simple identity layer on top of OAuth 2.0 that lets clients verify the identity of the end user based on the authentication performed by an authorization server. Its main addition is the ID token, a security token containing claims about the authentication of the user, represented as a JSON Web Token.
A JSON Web Token is a signed bundle of claims such as who issued it, who it is about, who it is for and when it expires. Because the signature comes from the issuer, a receiving app can check the token is genuine and unchanged.
Where it goes wrong
OAuth has had many security problems in practice. RFC 9700 is the current best-practice document: it updates and extends the threat model and security advice of the earlier OAuth documents, covers newer threats, and deprecates some modes of operation that are less secure or insecure. The lesson for builders: use a maintained library and follow current guidance, rather than implementing the flows yourself or copying an old tutorial.
For defenders, the lab checks apply: validate who issued a token, who it is for and when it expires, and keep scopes narrow.
Key points
- Single sign-on moves login to one trusted identity provider.
- OAuth 2.0 delegates limited access without sharing passwords.
- OpenID Connect adds identity: an ID token with claims, as a signed JSON Web Token.
- Follow current best practice (RFC 9700) and use maintained libraries.
Sources
- RFC 6749: The OAuth 2.0 Authorization Framework
- OpenID Connect Core 1.0
- RFC 9700: Best Current Practice for OAuth 2.0 Security
Practice in the labs
Watch a real sign-in flow in your browser, then protect an app with single sign-on and read a token critically.
- What really happens when you 'Sign in with Google': You watch a real 'Sign in with an account' flow in your browser's tools and see each redirect.
- Protect an app with Keycloak single sign-on (OpenID Connect): You put single sign-on in front of an app with OpenID Connect.
- Analyze a JWT for security flaws: You read a token's header and claims and check the things a careful receiver must check.
Knowledge check
- What does OAuth 2.0 mainly provide? Answer: Limited delegated access without sharing the password. RFC 6749: the framework enables a third-party application to obtain limited access to an HTTP service, on behalf of a resource owner or on its own behalf.
- What does OpenID Connect add on top of OAuth 2.0? Answer: An identity layer: an ID token with claims about the authentication of the user. OpenID Connect is a simple identity layer on OAuth 2.0 and its main extension is the ID token, represented as a JSON Web Token.
- You build an app that needs 'Sign in with an account'. What is the safest approach? Answer: Use a maintained library and follow current best practice. RFC 9700 deprecates less secure modes and updates the threat model; maintained libraries keep up with it and hand-written flows do not.
Back to the syllabus or see all classes.