angular2-jwt: AuthHttp don't have token in the ahthorization header?

I have configured the AuthHttp with the following code

import { routing } from './app.routes';
@NgModule({
  providers: [ApiService,  AuthHttpService,
    provideAuth({
        headerName: 'Authorization',
        headerPrefix: 'bearer',
        tokenName: 'auth_token',
        tokenGetter: (() => localStorage.getItem(this.tokenName)),
        //globalHeaders: [{ 'Content-Type': 'application/x-www-form-urlencoded' }],
        //noJwtError: true
    })
  ],
  bootstrap: [AppComponent]
})

However when I used the AuthHttp, my server side just show there is no ‘token’ in the Authorization header, anything I should note ?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 27 (12 by maintainers)

Most upvoted comments

Hi,

This issue helped me a lot to diagnose the case of authorization of OPTIONS in a CORS setup.

The OPTIONS request is generated automatically by the browser, and it does not include the token header.

To solve the case, since this OPTIONS request does not belong to the user context, it can be whitelisted and managed in a separated server security context of the application.

can you check whether your token is expired?

The issue is that the library doesn’t send token on “OPTIONS Preflight Request” but works properly on the others verbs (GET, POST, PUT, …). So, when the server receives a request with verb “OPTIONS” without a token, rejects the petition, even with CORS activated and configured to allow any origin, header, and method.

I have the same issue ! anyone have a solution ?