Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Identity Provider Basics

The whole lesson is free and interactive. Read it here, or press Start lab to run it for real in a live lab, with no account needed.

Container lab7 min read4 commands

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

One password for every app

You press Sign in with your college account on a new app, type your password on the college's own page, and land back in the app, signed in. The app never saw your password. The college's identity provider vouched for you. This lab has one, and an app that trusts it.

By the end of this lesson

Note

I can follow a sign-in through an identity provider and check what it sends back.

Key words

  • Identity provider: the service that signs people in for other apps.
  • OpenID Connect: the agreed way an app learns who signed in.
  • Authorisation code: a one-use value the app swaps for tokens.
  • ID token: a signed statement of who signed in.
  • Session cookie: the key a browser holds after sign-in.

Starter: what you already know

Note

Answer in your head. 1. What does a cookie let a website remember? 2. Why does a site store a hash and not the password? 3. What does a digital signature prove? Answers: that you signed in; so a stolen database does not give the passwords away; who made the data, and that nobody changed it.

Before you start

Note

Press Start the lab on the bar at the top of this lesson and wait until it says it is running. Dex is a service called idp, the Noticeboard is app, and the scripts are in tools. Each Run button below types its command into your lab's terminal, one after another in the same session. To watch them, or to type your own, press Open terminal on the bar.

1. The provider describes itself

Every OpenID Connect provider publishes a discovery document at a fixed address. Dex's says its issuer is http://idp:5556/dex, lists its endpoints, and says it signs tokens with RS256. An app reads this once instead of being told each address.

Command
curl -s http://idp:5556/dex/.well-known/openid-configuration

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

2. A sign-in, step by step

The script plays the browser and the Timetable app. The app sends the browser to Dex, Amira types her password into Dex's form, and Dex sends the browser back with code, state. The app then swaps the code at the token endpoint and gets access_token, expires_in, id_token, token_type.

Command
docker exec tools python3 steps/flow.py amira

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

3. Check the ID token

An ID token is only worth believing once it is checked. The script prints aud timetable, name Amira Haddad and exp - iat 600 seconds, then six lines starting ok: the signature, the issuer, the audience, the expiry, the nonce and the at_hash.

Command
docker exec tools python3 steps/idtoken.py amira

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

4. Two copies of one app

After sign-in the Noticeboard keeps a session cookie. The weak copy sets sid=<random>; Path=/ with no Secure, HttpOnly or SameSite flag. The safe copy sets all three, with a __Host- name. The module's lessons attack the weak copy and watch the safe one refuse.

Command
docker exec tools python3 steps/cookies.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Exit check

Tip

Answer without looking back. 1. Where did Amira type her password? 2. What came back to the app through the browser? 3. Name two checks made on the ID token. 4. Which flags did the weak copy's cookie lack? Answers: Dex's own form; a code and the state; any two of signature, issuer, audience, expiry, nonce and at_hash; Secure, HttpOnly and SameSite.

For teachers

Tip

This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. The lab is three small services, and nothing here marks itself: the student hands in a short report of their own copy, with three of the weak app's mistakes attacked, refused and spotted in the log, and the access review's findings decided, none of which this lesson does for them. Key learning points: 1. An identity provider signs people in for other apps and describes itself in a discovery document. 2. The browser carries only a code; the app swaps it for tokens. 3. An ID token is believed only after it is checked. Common mistake: thinking the app sees the password; it never does. Equipment: the lab and its terminal. Tip: ask students to say which of the six checks matters most before the third Run. The module Identity and access goes further in six lessons. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.

Teaching a class? Set these lessons for your students with marking and a lab for every student.