Authorization Header not added within Ionic 3
See original GitHub issueI am trying to implement JWT in my Ionic 3 app, and have been using angular2-jwt
successfully before (without HttpInterceptor
). But the master v1.0 branch
doesn’t seem to working, with all modules fully updated.
When doing as suggested in the Configuration for Ionic 2, there are no "Authorization: "
headers sent.
My app.module.ts has the following:
...
import { JwtModule, JWT_OPTIONS } from '@auth0/angular-jwt';
import { HttpClientModule } from '@angular/common/http';
...
const storage = new Storage({
name: 'myapp',
driverOrder: ['sqlite', 'indexeddb', 'websql'],
});
export function jwtOptionsFactory() {
return {
tokenGetter: () => {
return storage.get('id_token');
}
}
}
@NgModule({
declarations: [MyApp, AnnouncementModalPage],
imports: [
HttpClientModule,
JwtModule.forRoot({
jwtOptionsProvider: {
provide: JWT_OPTIONS,
useFactory: jwtOptionsFactory
}
}),...
Doing requests
Code for doing actual requests:
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { JwtHelperService } from '@auth0/angular-jwt'
...
@Injectable()
export class InspirationProvider {
constructor(public http: HttpClient,
private jwtHelper: JwtHelperService..) {
}
private fetchData(): Promise<Data[]> {
let token: string = this.jwtHelper.tokenGetter();
console.log("This outputs a Promise having the token", token);
return new Promise((resolve, reject) => {
this.http.get<Data[]>(INSPIRATION_URL)
.toPromise()
.then(data => {
resolve(data);
})
.catch((err) => {
// something bad happened
reject(err);
})
});
}
}
My ionic info
cli packages: (/Users/rogier/.nvm/versions/node/v6.9.3/lib/node_modules)
@ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
global packages:
cordova (Cordova CLI) : 7.0.1
local packages:
@ionic/app-scripts : 3.1.2
Cordova Platforms : android 6.2.3 browser 4.1.0 ios 4.4.0
Ionic Framework : ionic-angular 3.9.2
System:
Android SDK Tools : 25.2.2
ios-deploy : 1.9.2
Node : v6.9.3
npm : 3.10.10
OS : macOS Sierra
Xcode : Xcode 9.1 Build version 9B55
Problem: While looking at the request being made, there is no “authorization” header.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
Adding "Authorization" header in get request - Ionic Forum
I'm developing Ionic application with Spring framework back-end. Application is simple, check specified URI to check user is authenticated ...
Read more >Ionic 3.5.2 Authorization header missing in http request
I double check with the fiddler, I found a difference, that is the header Authorization is missing, it is not sent along with...
Read more >Developers - Authorization Header not added within Ionic 3 -
I am trying to implement JWT in my Ionic 3 app, and have been using angular2-jwt successfully before (without HttpInterceptor ). But the...
Read more >Authorisation Headers with Ionic using HTTP Interceptor and ...
In this Quick Win we will add a custom HTTP interceptor which will intercept all outgoing HTTP calls that our Ionic app makes....
Read more >Access-Control-Allow-Headers - HTTP - MDN Web Docs
In requests with credentials, it is treated as the literal header name " * " without special semantics. Note that the Authorization header...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got it working with my
app.module.ts
looking like this:Hi,
I’ve same problem, with whitelistedDomains…
export function jwtOptionsFactory() { return { tokenGetter: () => { return storage.get('access_token'); }, config: { whitelistedDomains: ['localhost:3001', 'notes.api', 'localhost:8100', '[::1]:80', 'localhost', 'localhost:8200'], } } }