I need to access Sonarqube Api from Angular 8 app but my request call is failing, I have tried following way:
app.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class AppService {
constructor(private http: HttpClient) { }
private baseUrl:string = 'https://sonarqube.[domain].com';
private issueSearch:string = '/api/issues/search?'
getIssues() {
const url:string = 'https://sonarqube.[domain].com//api/issues/search?[queryparams]'
return this.http.get(url);
}
}
Auth token was generated in sonarqube-->My Account -->Security
Authintercepter.ts
import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
import {Observable} from "rxjs";
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(){
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
req = req.clone({
setHeaders: {
Authorization: `Basic AUTH_TOKEN`
}
});
return next.handle(req);
}
}
but I'm not able to authenticate with this way, any idea what's going wrong here?
Thanks in advance.