Deviopath › Node.js

Bearer Token

Easy · Headers

APIs often send a token in the Authorization header as "Bearer <token>". Node lower-cases header names, so you read it from req.headers.authorization.

Write a function getBearerToken(headers) that returns the token, or null when:

- the header is missing

- the scheme is not Bearer (compare case-insensitively, so bearer works too)

- there is no token after the space

Next: Text to Base64