Only add authorization header if token exists
This commit is contained in:
@@ -49,13 +49,16 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
repo: string;
|
||||
}): Promise<PartialEntity[]> {
|
||||
const idToken = await this.identityApi.getIdToken();
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
} as { [header: string]: string };
|
||||
if (idToken) {
|
||||
headers.authorization = `Bearer ${idToken}`;
|
||||
}
|
||||
const response = await fetch(
|
||||
`${await this.discoveryApi.getBaseUrl('catalog')}/analyze-location`,
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${idToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
location: { type: 'url', target: repo },
|
||||
@@ -80,13 +83,16 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
location: string;
|
||||
}): Promise<void> {
|
||||
const idToken = await this.identityApi.getIdToken();
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
} as { [header: string]: string };
|
||||
if (idToken) {
|
||||
headers.authorization = `Bearer ${idToken}`;
|
||||
}
|
||||
const response = await fetch(
|
||||
`${await this.discoveryApi.getBaseUrl('catalog')}/locations`,
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${idToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
type: 'url',
|
||||
|
||||
@@ -39,11 +39,9 @@ export class FossaClient implements FossaApi {
|
||||
|
||||
private async callApi(path: string): Promise<any> {
|
||||
const apiUrl = `${await this.discoveryApi.getBaseUrl('proxy')}/fossa`;
|
||||
const headers: Record<string, string> = {
|
||||
authorization: await `Bearer ${this.identityApi.getIdToken()}`,
|
||||
};
|
||||
const idToken = await this.identityApi.getIdToken();
|
||||
const response = await fetch(`${apiUrl}/${path}`, {
|
||||
headers,
|
||||
headers: idToken ? { authorization: `Bearer ${idToken}` } : {},
|
||||
});
|
||||
if (response.status === 200) {
|
||||
return await response.json();
|
||||
|
||||
@@ -39,12 +39,15 @@ export class KubernetesBackendClient implements KubernetesApi {
|
||||
): Promise<any> {
|
||||
const url = `${await this.discoveryApi.getBaseUrl('kubernetes')}${path}`;
|
||||
const idToken = await this.identityApi.getIdToken();
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
} as { [header: string]: string };
|
||||
if (idToken) {
|
||||
headers.authorization = `Bearer ${idToken}`;
|
||||
}
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
authorization: `Bearer ${idToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers,
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
|
||||
|
||||
@@ -60,9 +60,7 @@ export class RollbarClient implements RollbarApi {
|
||||
const url = `${await this.discoveryApi.getBaseUrl('rollbar')}${path}`;
|
||||
const idToken = await this.identityApi.getIdToken();
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
authorization: `Bearer ${idToken}`,
|
||||
},
|
||||
headers: idToken ? { authorization: `Bearer ${idToken}` } : {},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user