Skip to content
CodeKruPro

Bearer tokens: missing credentials versus expiry

Automation taskEasy-MediumAsked in: Accenture, Capgemini, Infosys

A typical follow-up: "Your token expires in the middle of a run. What do you see, and what do you do?" This lesson puts a missing token and an expired token side by side, so you learn to tell the two 401 responses apart.

Bearer tokens: missing credentials vs expiry

03 · Authenticate and save a customer

Recommended first: Compare Basic authentication and an API key

Your goal: Bearer tokens: missing credentials vs expiry

Follow one request at a time. Send it yourself, then select that response before you answer.

  1. 1Send requests
  2. 2Submit answers

Start here: sign in to practise.

Jump to practice

What you will learn

A bearer token grants access to whoever presents it. Copy it from the login response into the Authorization header. It is not your CodeKru sign-in token. Editing the token text breaks it. That is not the same thing as waiting until it expires.

Your goals

  • Call a protected URL with the access token and without it.
  • Tell a damaged token apart from an expired token.

Before you start

Read the previous lesson first if you have not already. This course does not require programming.

Practice setup

These requests use the public TestKru teaching API. No workspace is needed unless a step says so. Leave the body empty for GET, HEAD and OPTIONS. Example people and emails are fictional. Changes to /api/users are simulated and are not saved.

Follow these steps

  1. Send POST https://testkru.com/api/auth/login with the teaching username and password from the API reference. Copy the token field. Do not copy it into your notes.
  2. Send GET https://testkru.com/api/auth/protected with header Authorization: Bearer and that token. Select that response.
  3. Send the same URL with no Authorization header. Select that response.
  4. Choose what editing a token by hand would prove.
  5. Submit Answers. This lesson does not include a real expired token. Do not change the token text and call the result expiry.

Investigate before concluding

First record the actual result for each case. Compare the body, headers and later state with the stated contract. Keep an observation separate from a prediction; use the model answer only after making your own attempt.

What to keep as evidence

  • The token is placed in the Authorization header.
  • The missing-token request uses the same URL.
  • Expiry is not confused with a damaged token.
References for this lesson

Finish this assignment

Select each named response with Use this response. Answer from those responses or the transcript on this page. Click Submit Answers. Your score is the percentage of checks that passed. Core checks are required to finish. Extra evidence checks are labelled. A saved 100/100 means every check passed. Continue opens the next lesson you can submit.

If something goes wrong
  • Change one part of the request at a time. If a check needs attention, read the note under it and compare it with the response you selected.
Self-review and independent variation
  • The token is placed in the Authorization header.
  • The missing-token request uses the same URL.
  • Expiry is not confused with a damaged token.

Explain why the shape of a token does not prove which service issued it.

Automatic checks verify the requests and answers configured for this lesson. The self-review is for your own reasoning. A score is not a certificate.

Open API reference

Practise and save your evidence

The lesson is public. Sign in to send requests and save progress. You will return to this lesson.

Sign in to practiseCreate an account