Skip to content

Full lab · 9 missions · about 40 minutes

Authentication: the full lab

Maya is a DevOps engineer at Harbor, a delivery company. You sign in as her, send her requests yourself, and watch what each of Harbor's services checks, from her password and session cookie to the tokens of a partner app that connects with OAuth 2.0.

Short on time? Start with the 10-minute exercise: missions 1 and 5 and the first steps of mission 6.

Before you start

You need Git, Docker with Compose (start Docker Desktop first, or the Docker service on Linux), about 2 GB of free disk space, at least 2 GB of memory for Docker, and port 8080 free on 127.0.0.1. For the browser missions, use Chrome, Edge or Firefox: Safari's engine didn't keep the lab's Secure session cookie on http://*.localhost addresses when I tested it.

Get the lab from my tutorials repository on GitHub, and start it from its folder:

git clone --depth 1 --branch 283-authentication-explained https://github.com/antonputra/tutorials.git
cd tutorials/lessons/283/lab
docker compose up -d --wait

Still have the tutorials folder from the exercise? Skip the git clone: the lab is in its lessons/283/lab folder.

The first start downloads about 400 MB and builds the lab's image: about a minute on a fast connection, a few minutes on a slower one. Later starts take about 20 seconds. init shows Exited: it only makes the lab's signing key, then stops.

Now open a shell inside the toolbox, the lab's terminal:

docker compose exec toolbox bash

The prompt starts with root@. The toolbox has curl, jq, base64 and the harbor helpers (harbor --help lists them). Run every command on this page there, unless a step says otherwise. On Windows, use PowerShell or Windows Terminal; in Git Bash, put winpty in front of the command.

  • The video shows .example names, and the lab uses .localhost names on port 8080: the video's api.harbor.example is api.harbor.localhost:8080 here. Only the ending changes, and the port is added.
  • Every value in the lab is fictional. Maya signs in as maya with the password demo-only. Never type a real password into the lab.
  • Your session IDs, keys and tokens will differ from the ones on this page.

If port 8080 is taken, the README.md in the folder shows how to move the lab to another port.

Mission 1. The first private request

3 minutes

You call Harbor's Status API, the program that reports the status of the tracking service, first without credentials, then with Maya's username and password.

  1. Ask for the status of the tracking service without logging in:

    curl -i http://api.harbor.localhost:8080/api/status/tracking
    
    HTTP/1.1 401 Unauthorized
    ...
    Www-Authenticate: Basic realm="Harbor"
    
    {"error":"unauthorized","reason":"no credentials"}
    

    The API doesn't know who you are, and Www-Authenticate tells you how to log in: with Basic authentication.

  2. Now send Maya's username and password:

    curl -i -u maya:demo-only http://api.harbor.localhost:8080/api/status/tracking
    
    HTTP/1.1 200 OK
    ...
    X-Harbor-Checked: Basic: password checked against the stored hash in 32 ms; permission status:read: yes
    
    {"service":"Tracking service","status":"Healthy"}
    

    The X-Harbor-Checked header is the lab's own: it shows what the API checked, here Maya's password against the hash Harbor stores. A real API doesn't send it.

  3. curl put the username and password into one header. See it, and decode its value:

    curl -sv -u maya:demo-only -o /dev/null http://api.harbor.localhost:8080/api/status/tracking 2>&1 | grep Authorization
    echo bWF5YTpkZW1vLW9ubHk= | base64 -d; echo
    
    > Authorization: Basic bWF5YTpkZW1vLW9ubHk=
    maya:demo-only
    
  4. Try a wrong password:

    curl -i -u maya:wrong http://api.harbor.localhost:8080/api/status/tracking
    

    You get 401 again, with "reason":"wrong username or password".

  5. See your last two requests as the Status API received them, newest first:

    harbor requests 2
    
    {"time": "15:55:19 UTC", "method": "GET", "path": "/api/status/tracking", "authorization": "Basic bWF5YTp3cm9uZw==", "x-api-key": null, "status": 401, ...}
    {"time": "15:55:19 UTC", "method": "GET", "path": "/api/status/tracking", "authorization": "Basic bWF5YTpkZW1vLW9ubHk=", "x-api-key": null, "status": 200, ...}
    

    The password arrived with each request: bWF5YTp3cm9uZw== decodes to maya:wrong.

Why. Base64 is an encoding, not encryption, so anyone who sees the request can read the password. That's why Basic auth needs HTTPS, as the video says; here the requests never leave Docker. HTTP is stateless, so every request carries the password again, and Harbor checks it against the stored hash every time, which is slow on purpose: those are the milliseconds in X-Harbor-Checked.

Mission 2. A browser login

4 minutes

You sign in to Harbor's dashboard with its password form, then compare what your browser keeps with what the server keeps.

  1. Open http://dashboard.harbor.localhost:8080. You're not signed in, so the dashboard sends you to its sign-in page.
  2. Open DevTools, the browser's own inspection tools (F12, or Cmd+Option+I on a Mac), and select the Network tab.
  3. Type maya in Username and demo-only in Password, then press Sign in. The dashboard says "Signed in as Maya, with a password."
  4. In the Network tab, click the login request. Its response headers include:

    Set-Cookie: session=WXUtTvtOVBN3jU3q1rXeIcdhpHqmvuO1o6RAeH4V08g; Secure; HttpOnly; SameSite=Lax; Path=/
    

    The dashboard checked the password once and created a session, a record on its server. Set-Cookie tells your browser to store a cookie, a small value it sends back with later requests. This cookie holds only the session's ID, a long random value.

  5. Press Refresh on the Tracking service card, then click the first request in the Network list, the page itself. Its request headers carry the cookie, and no password:

    Cookie: session=WXUtTvtOVBN3jU3q1rXeIcdhpHqmvuO1o6RAeH4V08g
    
  6. Find the cookie in Application > Cookies in Chrome and Edge, or Storage > Cookies in Firefox. HttpOnly and Secure are on, and SameSite is Lax. Now select the Console tab and type:

    document.cookie
    

    You get an empty string: the page's JavaScript can't read the session cookie.

  7. Click your session record, at the bottom of the dashboard. It's a lab-only page that shows the server's record as JSON. In Chrome, tick Pretty-print to lay it out; Edge and Firefox lay out JSON themselves.

    {
      "lab_only": "Harbor's record for this session, kept on the server. ...",
      "session_id": "WXUtTv…",
      "user": "maya",
      "signed_in_with": "a password",
      "created": "15:55:39 UTC",
      "expires": "16:25:39 UTC",
      "expires_in_seconds": 1792,
      "created_by": "dashboard-b",
      "csrf_token": "ilEjth…"
    }
    

Why. The password crossed the network once, at sign-in; after that, the session ID is the credential, as in the video. The browser holds the ID, and the server holds the record it points to: Maya and an expiry time, 30 minutes later. HttpOnly keeps page scripts away from the cookie, so a script someone injects can't copy it, and with Secure the browser sends it only over HTTPS; browsers count *.localhost addresses as secure, so it works here on plain HTTP.

Extra: two servers, one session

Press Refresh a few times and watch Served by under the title. The lab's gateway sends each request to dashboard-a and dashboard-b in turn, and both find Maya's session, because they share one session store, a database both servers consult. Your session record's created_by names the server that created it.

Mission 3. A request from another site

3 minutes

While Maya is signed in, you open another website, whose hidden form asks the dashboard to send her status alerts to a coupons address.

  1. On the dashboard, Send my status alerts to shows maya@harbor.example.
  2. In the same browser, open http://coupons.localhost:8080. The page says "Loading your coupon...", and a moment later its hidden form sends the change to the dashboard. You land on the dashboard's Not signed in page: "No valid session came with this request, so Harbor doesn't know who is asking. Nothing was changed." A lab-only note under it names the coupons site, and says Maya's own sign-in is untouched.
  3. See how that request reached the dashboard:

    curl -s http://dashboard.harbor.localhost:8080/lab/requests | jq '.[] | select(.path == "/alerts")'
    
    {
      "time": "15:56:44 UTC",
      "server": "dashboard-b",
      "method": "POST",
      "path": "/alerts",
      "cookie": "(none)",
      "origin": "http://coupons.localhost:8080",
      "sec-fetch-site": "cross-site",
      "status": 401,
      "note": "no valid session: rejected"
    }
    
  4. Open http://dashboard.harbor.localhost:8080 again. Maya is still signed in, and her alerts still go to maya@harbor.example.

Why. coupons.localhost and dashboard.harbor.localhost are different sites, and your browser marked the request as one that started on another site: Sec-Fetch-Site: cross-site. With SameSite=Lax, the cookie is left out when another site starts a request like that, so Harbor didn't know who was asking and changed nothing. This is the attack from the video, cross-site request forgery (CSRF): another site makes Maya's browser send a request in her name.

  1. Make the next sign-in's cookie SameSite=None:

    harbor lab samesite none
    
  2. On the dashboard, press Log out, then sign in again as maya / demo-only. In DevTools, the new cookie's SameSite is None.

  3. Open http://coupons.localhost:8080 again. This time you land on Refused: "Maya's cookie came with this request, but it didn't come from Harbor's own page (Origin: http://coupons.localhost:8080) and it carried no valid form token for this session. Nothing was changed."
  4. Run the mission's /lab/requests command again. The new request shows "cookie": "session=K3fFL5…" and "status": 403.
  5. Put the setting back. The next sign-in gets a Lax cookie again:

    harbor lab samesite lax
    

The cookie came along, so Harbor's own check decided, as in the video: a request that changes data must come from Harbor's own page, which the browser names in the Origin header, and carry the session's form token, a random value in Harbor's own forms. The coupons page has neither, and the dashboard's Save button sends both.

Mission 4. Log out and replay

3 minutes

You copy Maya's session ID into the terminal, log out in the browser, and send the old ID again.

  1. In DevTools, copy the value of the session cookie: double-click the value, then copy it.
  2. Send it from the toolbox in place of SESSION_ID. harbor replay asks the dashboard for the status with that cookie alone, and prints the request and the answer:

    harbor replay SESSION_ID
    
    > GET /status HTTP/1.1
    > Host: dashboard.harbor.localhost:8080
    > Cookie: session=K3fFL5SmkVBBVdHwhnwjxjC3KZZH-nRjldl_8pLph8M
    
    < HTTP/1.1 200 OK
    {"status":"Tracking service — Healthy","ok":true,"served_by":"dashboard-a"}
    

    The terminal isn't Maya's browser, yet the ID alone gets her status.

  3. On the dashboard, press Log out. You're back on the sign-in page, and the cookie is gone from DevTools.

  4. Send the old ID again:

    harbor replay SESSION_ID
    
    ...
    < HTTP/1.1 401 Unauthorized
    < Www-Authenticate: Cookie realm="Harbor dashboard", form-action="/login", cookie-name="session"
    {"error":"unauthorized","reason":"no valid session"}
    
  5. Sign in again and copy the new session value. It's a different ID: harbor replay gets 200 with the new one, and 401 with the old one.

Why. As in the video, logging out ended the session on the server, so every copy of the old ID stopped working, the one in your terminal included. Clearing the cookie removes only one browser's copy. The 401's challenge is in Harbor's own format, because no standard one describes a sign-in form: it names the way back in, the form at /login and its cookie, session.

Extra: a session that ends on its own

  1. Make the next session last one minute:

    harbor lab session-ttl 60
    
  2. Press Log out, sign in again, and wait a minute.

  3. Press Refresh. The dashboard sends you to the sign-in page, although DevTools still shows the cookie.
  4. Sign in again. This session lasts the usual 30 minutes.

Harbor checks the expiry in its record on every request, whatever the browser still holds.

Mission 5. The reporting job's own key

3 minutes

You run Harbor's reporting job, a program that reads the status on a schedule with its own API key, a secret value tied to the job's own record, instead of Maya's password.

  1. Run the job's request:

    harbor job
    
    > GET /api/status/tracking HTTP/1.1
    > Host: api.harbor.localhost:8080
    > X-API-Key: job_demo_4Kx9Qe2mVt7Lp1Zr8Ws3
    
    < HTTP/1.1 200 OK
    < X-Harbor-Checked: API key: looked up, active; permission status:read: yes
    {"service":"Tracking service","status":"Healthy"}
    

    The job sends its key in the X-API-Key header and gets 200 OK.

  2. Now the job asks to change a service setting:

    harbor job --change
    
    > PUT /api/settings/tracking HTTP/1.1
    ...
    < HTTP/1.1 403 Forbidden
    < X-Harbor-Checked: API key: looked up, active
    {"error":"forbidden","reason":"reporting job may not change the tracking service's settings"}
    

    The API knows exactly who is calling, and the answer is still no: the key can only read.

  3. A key the API doesn't know gets 401 instead:

    harbor job --key job_demo_madeup
    
    ...
    < HTTP/1.1 401 Unauthorized
    < Www-Authenticate: ApiKey realm="Harbor", header="X-API-Key"
    {"error":"unauthorized","reason":"unknown API key"}
    
  4. The key's record shows what it may do:

    harbor key show
    
    [
      {
        "key": "job_demo_4Kx9Qe2mVt7Lp1Zr8Ws3",
        "owner": "reporting job",
        "permissions": [
          "status:read"
        ],
        "active": true
      }
    ]
    

Why. 401 means "who are you?", and 403 means "I know who you are, and you can't do that": the video's two checks, authentication and authorization. The key belongs to the job, not to Maya, and its record allows only status:read, so Harbor can limit or end the job's access without touching Maya's password.

Extra: rotate the key

harbor key rotate
harbor job
harbor job --key job_demo_4Kx9Qe2mVt7Lp1Zr8Ws3

harbor key rotate makes a new key for the job and revokes the old one. The job now sends its new key and gets 200. The old key gets 401 and this API key was revoked. That's how you replace a leaked key.

Mission 6. Bearer tokens and JWTs

8 minutes

You call the Status API with access tokens, credentials that stand for permitted access: an opaque one, then JWTs that you decode, edit and revoke.

  1. A Bearer token goes in the Authorization: Bearer header, and whoever holds it gets in, so it's handled like a password. The dashboard's backend calls the API with an opaque token, a random string that means nothing on its own:

    curl -i -H "Authorization: Bearer $(harbor token --opaque)" http://api.harbor.localhost:8080/api/status/tracking
    
    The dashboard backend's opaque token, prepared for the example.
    HTTP/1.1 200 OK
    ...
    X-Harbor-Checked: opaque token: looked up, active; permission status:read: yes
    

    The API looked the token up in its own records.

  2. The other kind is a JWT (JSON Web Token), an access token that carries its own information. The helper prepares one, signed with the key of Harbor Sign-in, the company's sign-in service; step 7 gets one from Harbor Sign-in itself. Make one and decode it:

    TOKEN=$(harbor token)
    harbor jwt decode "$TOKEN"
    
    Prepared for the example, signed with Harbor Sign-in's key: an access token for the Status API, valid for 5 minutes.
    Decoded, not verified: anyone holding the token can read this.
    header: {
      "alg": "RS256",
      ...
    }
    payload: {
      "exp": 1794672253,
      "iat": 1794671953,
      ...
      "iss": "http://login.harbor.localhost:8080/realms/harbor",
      "aud": "harbor-status-api",
      "sub": "maya-01",
      ...
      "scope": "status:read"
    }
    iat: 2026-11-14 15:59:13 UTC (now)
    exp: 2026-11-14 16:04:13 UTC (in 300 s)
    signature: MzKCufDTdADrEA7P... (256 bytes)
    

    A JWT carries claims, fields that say who and what it's for: who issued it (iss), whose token it is (sub), which API it's for (aud), what it allows (scope), when it was issued (iat) and when it expires (exp, 5 minutes later). The token lasts 5 minutes and is kept only in this shell. If a command below says the token has expired or three parts, run TOKEN=$(harbor token) again.

  3. Send it:

    curl -i -H "Authorization: Bearer $TOKEN" http://api.harbor.localhost:8080/api/status/tracking
    
    HTTP/1.1 200 OK
    ...
    X-Harbor-Checked: JWT: signature (key SW_pY7do...), issuer, audience, expiry (in 299 s); permission status:read: yes
    

    The API checked the token on its own, with Harbor Sign-in's public key. It didn't ask Harbor Sign-in about this token.

  4. With the same token, ask to change the settings:

    curl -i -X PUT -H "Authorization: Bearer $TOKEN" http://api.harbor.localhost:8080/api/settings/tracking
    
    HTTP/1.1 403 Forbidden
    ...
    Www-Authenticate: Bearer realm="Harbor", error="insufficient_scope", scope="settings:write"
    ...
    {"error":"forbidden","reason":"maya-01 may not change the tracking service's settings"}
    

    The token is genuine, but its scope doesn't include settings:write.

  5. Give the token more permissions and keep its old signature. Decode the result, then send it:

    BAD=$(harbor jwt edit "$TOKEN" scope="status:read settings:write")
    harbor jwt decode "$BAD"
    curl -i -X PUT -H "Authorization: Bearer $BAD" http://api.harbor.localhost:8080/api/settings/tracking
    

    The decoded payload says "scope": "status:read settings:write", with the same signature, and the API refuses it:

    HTTP/1.1 401 Unauthorized
    ...
    Www-Authenticate: Bearer realm="Harbor", error="invalid_token"
    
    {"error":"unauthorized","reason":"the signature doesn't match the token's content"}
    
  6. Send a token made for another API, then one that expired 5 minutes ago:

    curl -i -H "Authorization: Bearer $(harbor token --other-api)" http://api.harbor.localhost:8080/api/status/tracking
    curl -i -H "Authorization: Bearer $(harbor token --expired)" http://api.harbor.localhost:8080/api/status/tracking
    

    Both get 401: first the token was made for harbor-billing-api, not for harbor-status-api, then the token has expired. The first token's signature is fine, but its audience is wrong.

  7. Get a new token from Harbor Sign-in itself. The helper signs in as Maya the way the dashboard does, and prints each step:

    FRESH=$(harbor token --fresh)
    
    Signing in as Maya on Harbor Sign-in with the dashboard's code flow, the way a browser would (lab helper):
    > GET http://login.harbor.localhost:8080/realms/harbor/protocol/openid-connect/auth?response_type=code&client_id=har…
    < 200 OK
    > POST http://login.harbor.localhost:8080/realms/harbor/login-actions/authenticate?session_code=FXP2G_HubBuvlJEmT3l3n…  (form: username=maya&password=demo-only&credentialId=)
    < 302 Found, Location: http://dashboard.harbor.localhost:8080/auth/callback?state=nYMruz8B6xLmpyYq&session_state=T8Ktt9fp309ylnd0z3O1…
    > POST http://login.harbor.localhost:8080/realms/harbor/protocol/openid-connect/token  (form: grant_type=authorization_code, code=1b5fc039-8…, code_verifier=gYvn48Re…; the dashboard's client ID and secret in Authorization: Basic)
    < 200 OK
    

    The token itself went into FRESH. Missions 7 and 8 take these steps in your browser.

  8. Revoke the token at Harbor Sign-in:

    harbor revoke "$FRESH"
    
    Revoking the token at Harbor Sign-in (RFC 7009), as the dashboard client that received it.
    > POST /realms/harbor/protocol/openid-connect/revoke HTTP/1.1
    ...
    > token=eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lk...&token_type_hint=access_token
    
    < HTTP/1.1 200 OK
    
  9. Send the revoked token to the Status API:

    curl -i -H "Authorization: Bearer $FRESH" http://api.harbor.localhost:8080/api/status/tracking
    
    HTTP/1.1 200 OK
    ...
    X-Harbor-Checked: JWT: signature (key SW_pY7do...), issuer, audience, expiry (in 298 s); permission status:read: yes
    

    It still works.

  10. Wait until the token's exp, 5 minutes after step 7 (harbor jwt decode "$FRESH" shows how long is left; the extra below fills the wait), then send it again:

    curl -i -H "Authorization: Bearer $FRESH" http://api.harbor.localhost:8080/api/status/tracking
    
    HTTP/1.1 401 Unauthorized
    ...
    {"error":"unauthorized","reason":"the token has expired"}
    

Why. Decoding isn't verifying: anyone can read the claims, but only Harbor Sign-in's private key makes a signature that matches them, so the edited token failed. A genuine signature isn't enough either: the issuer, the audience, the expiry and the scope must fit the request. Because the API checks a JWT locally, a revoked token is still accepted until it expires, like the video's token: revoked a minute after it was created, it failed only at the five-minute mark. That's why access tokens are short-lived.

Extra: ask Harbor Sign-in about every token

  1. Switch the Status API to introspection: after its own checks, it asks Harbor Sign-in whether each token is still active.

    harbor api-check introspect
    
  2. Send the revoked token, then a new one:

    curl -i -H "Authorization: Bearer $FRESH" http://api.harbor.localhost:8080/api/status/tracking
    curl -i -H "Authorization: Bearer $(harbor token --fresh)" http://api.harbor.localhost:8080/api/status/tracking
    

    The revoked token fails at once, with Harbor Sign-in says this token is no longer active. The new one gets 200, and its X-Harbor-Checked ends with and Harbor Sign-in says it's still active; permission status:read: yes.

  3. Switch back before mission 7:

    harbor api-check local
    

Introspection ends a token at once, and it costs one more request to Harbor Sign-in for every API call.

Mission 7. The partner connects

8 minutes

You connect a partner's reporting app to Harbor with OAuth 2.0, the standard way for an app to get access that a person approves, so the partner reads the status without ever seeing Maya's password.

  1. Open http://reports.partner.localhost:8080 and press Connect Harbor.
  2. Before your browser goes anywhere, the page shows the request it's about to make:

    GET http://login.harbor.localhost:8080/realms/harbor/protocol/openid-connect/auth
    
    response_type          code
    client_id              partner-reports
    redirect_uri           http://reports.partner.localhost:8080/callback
    scope                  status:read
    state                  ZWGtRhQ19CIS_IVAPeYblQ
    code_challenge         TzLA4gd4l5kb5VCmzKiaHvuMn5n6tPpNwkXWN6KSiQg
    code_challenge_method  S256
    

    state is a random value that ties the answer to this attempt. code_challenge is PKCE (Proof Key for Code Exchange): the SHA-256 hash of a random secret, the verifier, which the partner's backend keeps. As the page says, the verifier and the partner's client secret aren't in the request.

  3. Press Continue to Harbor Sign-in. The address bar now shows login.harbor.localhost: on Harbor Sign-in's own page, type maya in Username and demo-only in Password, then press Sign In.

  4. Harbor Sign-in asks: Grant Access to Partner Reports, with Read tracking status. Press Yes. Harbor Sign-in stores a grant, the access Maya approved for the partner.
  5. You're back on the partner's site, on Connected to Harbor. The address bar carries the state and a code, and no token:

    http://reports.partner.localhost:8080/callback?state=ZWGtRhQ19CIS_IVAPeYblQ&session_state=6fyujTU8bKvyLV2BQwhwzACr&iss=http%3A%2F%2Flogin.harbor.localhost%3A8080%2Frealms%2Fharbor&code=1eb0d551-a66d-44e0-71c3-9ec6ce1887d2.6fyujTU8...
    

    The backend's token exchange shows what happened next: the partner's backend sent the code to Harbor Sign-in's token endpoint on a direct connection, with the partner's client ID and secret and the verifier.

    {
      "request": "POST http://login.harbor.localhost:8080/realms/harbor/protocol/openid-connect/token",
      "client_authentication": "Basic partner-reports:part… (HTTP Basic)",
      "form": {
        "grant_type": "authorization_code",
        "code": "1eb0d551-a…",
        "redirect_uri": "http://reports.partner.localhost:8080/callback",
        "code_verifier": "o0FxwnQv…"
      },
      "answer": {
        "status": 200,
        "access_token": "eyJhbGciOiJS…",
        "expires_in": 300,
        "refresh_expires_in": 1800,
        "refresh_token": "eyJhbGciOiJI…",
        ...
    

    Under it, the Report card says "Tracking service — Healthy".

  6. See the claims of the access token the partner's backend keeps:

    harbor partner tokens | jq .access_token_claims
    
    {
      ...
      "aud": "harbor-status-api",
      "sub": "maya-01",
      "typ": "Bearer",
      "azp": "partner-reports",
      ...
      "scope": "status:read"
    }
    

    It's Maya's token, for the Status API, read-only, and given to the partner (azp).

  7. Press Go to Partner Reports, then Get a new access token: "Harbor Sign-in gave a new access token for the refresh token, valid for 300 s. Maya didn't have to sign in again." A refresh token is a separate credential that gets new access tokens. Press Back to the report, then Send the refresh token to the Status API: "The Status API answered 401: signed with a key Harbor Sign-in doesn't publish".

  8. Harbor disconnects the partner, which removes Maya's grant:

    harbor partner disconnect
    
  9. Press Back, then Get a new access token again. You land on Refresh refused: "Harbor Sign-in answered 400: invalid_grant, Session doesn't have required client". Press Back: the report still says "Tracking service — Healthy".

Why. As the video explains, a redirect exposes all its data, so the browser carries only a code, which expires fast and is good for a single use, and the tokens travel directly from Harbor Sign-in to the partner's backend. Harbor Sign-in hashes the verifier, and the result has to match the challenge from the start, so a code stolen from Maya fails in anyone else's attempt. After the disconnect, Harbor Sign-in refuses the refresh token, while the access token is accepted until it expires, as the revoked JWT was in mission 6.

Extra: a wrong verifier, and a code used twice

Do these after the mission: the code reuse at the end cancels the partner's refresh token, so mission 9 has you connect again.

  1. Make the partner's next connection send a wrong verifier:

    harbor partner wrong-verifier on
    
  2. On the partner's page, press Connect Harbor again, then Continue to Harbor Sign-in. Harbor Sign-in doesn't ask for the password, because Maya is still signed in there, but it asks for her consent again, because the disconnect removed her grant. Press Yes. You land on Not connected: "Harbor Sign-in refused the code exchange: invalid_grant, PKCE verification failed: Code mismatch".

  3. Press Back, Connect Harbor again and Continue to Harbor Sign-in. The verifier is right again, and you come straight back, connected.
  4. Send the last code to Harbor Sign-in a second time:

    harbor partner reuse-code
    
    {
      "code_used_again": {
        "status": 400,
        "error": "invalid_grant",
        "error_description": "Code not valid"
      },
      "the_first_refresh_token_now_gets": "400: invalid_grant, Session doesn't have required client",
      "the_first_access_token_at_the_status_api": "200: Tracking service — Healthy",
      ...
    }
    

A code works once. When it comes back, Harbor Sign-in also cancels what it gave for it, so the refresh token stops working; the access token, checked locally, still passes.

Mission 8. Company sign-in and one complete request

6 minutes

You switch the dashboard to Sign in with Harbor, which uses OpenID Connect, an identity layer on OAuth 2.0 that tells an app who signed in, then follow one press of Refresh from the browser to the Status API and back.

  1. Switch the dashboard's sign-in:

    harbor lab sign-in harbor
    
  2. Open http://dashboard.harbor.localhost:8080. If you're signed in, press Log out: the switch changes only the next sign-in. The sign-in page now has only Sign in with Harbor. Press it.

  3. You're back on the dashboard at once, and it says "Signed in as Maya, with Harbor Sign-in." Harbor Sign-in didn't ask for the password, because Maya signed in there in mission 7, and one sign-in serves all of Harbor's apps (single sign-on). It didn't ask for consent either, because the dashboard is Harbor's own app. If it does ask for the password, type maya and demo-only there.
  4. In DevTools, the dashboard's only cookie is session. In the Console, check the page's storage too:

    [localStorage.length, sessionStorage.length, document.cookie]
    

    You get two zeros and an empty string: the browser holds no token.

  5. Click your session record. The tokens are on the server, with the session:

    {
      ...
      "signed_in_with": "Harbor Sign-in",
      ...
      "tokens_kept_with_the_session": {
        "id_token": {
          "value": "eyJhbGciOiJS…",
          "claims": {
            ...
            "aud": "harbor-dashboard",
            "sub": "maya-01",
            "typ": "ID",
            ...
            "nonce": "VGsckoZ_7fQxiUZoo6kroQ",
            ...
        "access_token": {
          "value": "eyJhbGciOiJS…",
          "claims": {
            ...
            "aud": "harbor-status-api",
            ...
            "scope": "openid status:read"
          },
          ...
        "refresh_token": {
          "value": "eyJhbGciOiJI…",
          "goes_only_to": "Harbor Sign-in"
        }
    

    The ID token is a JWT about the sign-in, made for the dashboard (aud). Its nonce is the random value the dashboard sent when the sign-in started, so the dashboard knows the answer belongs to its own attempt.

  6. Copy the new session value from DevTools, and send the ID token to the Status API:

    ID_TOKEN=$(harbor session SESSION_ID --id-token)
    curl -i -H "Authorization: Bearer $ID_TOKEN" http://api.harbor.localhost:8080/api/status/tracking
    
    The ID token kept with this session on the dashboard's server (the lab's teaching view; Maya's browser never had it).
    HTTP/1.1 401 Unauthorized
    ...
    {"error":"unauthorized","reason":"the token was made for harbor-dashboard, not for harbor-status-api"}
    
  7. With the dashboard open in your browser, make the session's access token expire now, so the next refresh has to renew it:

    harbor lab expire-access
    
  8. Press Refresh once. Then read that refresh's trace, the lab's record of each step:

    curl -s -b "session=SESSION_ID" http://dashboard.harbor.localhost:8080/lab/trace | jq -r '.steps[] | .step + ": " + .detail'
    
    browser -> dashboard: GET /, Cookie: session=sy76Dw…
    dashboard: found the session in the shared store: maya, valid for another 1383 s
    dashboard -> Harbor Sign-in: the access token has expired: POST /token, grant_type=refresh_token, with the dashboard's client ID and secret
    Harbor Sign-in -> dashboard: a new access token, valid for 300 s; Maya never noticed
    dashboard -> Status API: GET /api/status/tracking, Authorization: Bearer eyJhbGciOi… (Maya's access token (a JWT from Harbor Sign-in))
    Status API: checked: JWT: signature (key SW_pY7do...), issuer, audience, expiry (in 299 s); permission status:read: yes
    Status API -> dashboard: 200: Tracking service, Healthy
    dashboard -> browser: Tracking service — Healthy
    

    The trace keeps only the last load of the dashboard. If yours has no Harbor Sign-in steps, run harbor lab expire-access again and press Refresh once.

Why. One refresh used several mechanisms, each answering its own question, as at the end of the video. The session cookie said which login the request belonged to, OpenID Connect had told the dashboard who signed in, and OAuth's code flow had given it the access token, a JWT sent with Bearer and renewed with the refresh token. Your browser held only the cookie, and every token stayed on the dashboard's server.

Mission 9. Retire the reporting job

3 minutes

Harbor is retiring the reporting job: you stop only the job, while Maya's dashboard and the partner keep working.

This mission is a challenge, with no steps. First, check that all three callers work now:

harbor check
Each caller sends GET /api/status/tracking now, with its own credential; the Status API's answers (- when no request reached it):
reporting job (its API key)                  200  Tracking service — Healthy
dashboard (maya's session sy76Dw…)           200  Tracking service — Healthy
partner (its access token)                   200  Tracking service — Healthy

If the partner's row says to connect again, open http://reports.partner.localhost:8080 and press Connect Harbor again, then Continue to Harbor Sign-in (and Yes, if Harbor Sign-in asks). If no dashboard row says 200, sign in to the dashboard again.

You're done when harbor check shows 401 for the reporting job, and 200 for the dashboard and the partner.

Show one way

Revoke the job's key in its credential record, then check again:

harbor key revoke
harbor check
...
reporting job (its API key)                  401  this API key was revoked
dashboard (maya's session sy76Dw…)           200  Tracking service — Healthy
partner (its access token)                   200  Tracking service — Healthy

The job had its own credential, so revoking it touched nothing else: Maya's session and the partner's token still work. It took effect at once: the API looks up the key on each request, the same way the dashboard looks up a session. A JWT checked locally, as in mission 6, is accepted until it expires.

Clean up

Type exit to leave the toolbox, then delete the lab, its signing key included:

docker compose down -v

To delete the lab's images as well, run docker compose down -v --rmi all instead. Then you can delete the tutorials folder.

To do the missions again without starting over, run harbor lab reset in the toolbox. It puts every switch back to its starting value and gives the job a working key; sessions and connections stay as they are.

Newsletter · Free

Get new exercises by email

Every new video comes with an exercise like this one.

Loading signup form…

Free. Unsubscribe anytime. Form not loading? Subscribe here.