nginx / nginx/njs-examples

Authorization Header Not Sent

Open
#21 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
694
Forks
82
PR merge metrics
No merged PRs in 30d

Description

let reply = await r.subrequest('/auth' , {
         method: 'POST',
         body: JSON.stringify({ username: "test", password: "test" })},);
    let response = JSON.parse((reply.responseBody));
    let token = response['token'];

    if (!token) {
     throw new Error("Failed to retrieve token from authentication endpoint");
    }

    var subrequestHeaders = {
      "Authorization": "Bearer " + token,
      "Content-Type": "application/json"
     };
    let backend_reply = await r.subrequest('/api/users', {
      headers: subrequestHeaders
      });

r.return(backend_reply.status, JSON.stringify(backend_reply));

 }catch (e) {
    r.return(500, e);
} 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown njs subrequest sequence: obtain the token from /auth, pass the Authorization header to /api/users, and inspect what the backend receives. Determine whether the header is forwarded as expected and verify completion by confirming that /api/users receives the Bearer token.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nginx
Domain
api, authorization, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.