Angular-auth-oidc-client: Version 3.x breaks HttpClient Interceptor

Created on 24 Oct 2017  路  3Comments  路  Source: damienbod/angular-auth-oidc-client

I upgraded to the new 3.x Version today and recognized that it breaks my AuthInterceptor for HttpClient. It seems the use of HttpClient instead of Http is the reason for a cyclic dependency Angular can't resolve.
As a reference this is the code of my Interceptor.

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
    constructor(private oidcSecurityService: OidcSecurityService) {

    }

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        let token = this.oidcSecurityService.getToken();
        let requestToForward = req;
        if (token !== "") {
            let tokenValue = "Bearer " + token;
            requestToForward = req.clone({ setHeaders: { "Authorization": tokenValue}});
            //console.log("Auth intercept headers: " + req.headers);
        }

        return next.handle(requestToForward);
    }
}

As I think my usecase is quite common, it would be nice to have some mechanism to work around this cyclic dependency. Just let me know if I can help with a pull request.

enhancement documentation

Most helpful comment

Thank you for the fast response. Seems like I gave up too soon while researching this issue.. It'll be nice to include this tip in the doc. I'll create a PR for that.

All 3 comments

@haidelber That's normal, and it doesn't need a workaround in the library, but in your interceptor. Try this solution: https://github.com/angular/angular/issues/18224#issuecomment-316957213

Thank you for the fast response. Seems like I gave up too soon while researching this issue.. It'll be nice to include this tip in the doc. I'll create a PR for that.

merged, thanks!

Was this page helpful?
0 / 5 - 0 ratings