So first i had to provide a headername, in my root-module angular2-jwt config looked like this:
provideAuth({
headerName: 'BearerToken',
headerPrefix: '',
tokenName: '',
tokenGetter: () => {
return JSON.parse(localStorage.getItem('bearerToken'));
},
globalHeaders: [{'Content-Type': 'application/json'}],
noJwtError: true,
noTokenScheme: true
})
Still not working. After some research i found the header name should be 'Authorization' and the tokenName should be 'Bearer'. Ok lets try like this:
provideAuth({
headerName: 'Authorization',
headerPrefix: '',
tokenName: 'Bearer',
tokenGetter: () => {
return JSON.parse(localStorage.getItem('bearerToken'));
},
globalHeaders: [{'Content-Type': 'application/json'}],
noJwtError: true,
noTokenScheme: true
})
Still my ControllerMethod with the Authorize-Tag was not reached. Ok, one last try, maybe it works when i add 'Bearer ' manually:
provideAuth({
headerName: 'Authorization',
headerPrefix: '',
tokenName: 'Bearer',
tokenGetter: () => {
var token: string = JSON.parse(localStorage.getItem('bearerToken'));
return 'Bearer ' + token;
},
globalHeaders: [{'Content-Type': 'application/json'}],
noJwtError: true,
noTokenScheme: true
})
and ... bombe surprise ... it worked ;) Playing around a little bit more i found out that tokenName can be empty or can contain anything else.