I recently updated an app to Ionic Capacitor (angular) and before I was able to get the accessToken to use an HttpInterceptor like so:
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AuthService } from './auth.service';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
public constructor(
private authService: AuthService
) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
req = req.clone({
setHeaders: {
'Authorization': `Bearer ${this.authService.accessToken}`,
},
});
return next.handle(req);
}
}
accessToken is set in auth.service.ts in older Auth0 files:
“@auth0/cordova”: “^0.3.0”
“auth0-js”: “^9.13.2”
I’m now using Ionic Capacitor and it’s using:
“@auth0/auth0-angular”: “^1.8.2”,
The “access_token” that is returned from getAccessTokenSilently() is a much smaller string and I’m not sure where/how to get the accessToken to use as bearer to pass into my Interceptor.