Skip to content

Commit

Permalink
Fix authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Feb 2, 2021
1 parent ebeb96d commit 4c4b849
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/store.ts
Expand Up @@ -71,30 +71,28 @@ export class GraphDbDataStore implements Store {
}

private async authenticate(): Promise<Headers> {
if (this.username === null || this.password === null) {
if (this.username === undefined || this.password === undefined) {
return new Headers();
}

if (this.token !== undefined) {
return new Headers();
}

const response = await fetch(this.url + '/rest/login/' + this.username, {
method: 'POST',
headers: {'X-Graphdb-Password': this.password!},
});

if (!response.ok) {
throw Error(
'Could not authenticate username ' +
this.username +
' with GraphDB; got status code ' +
response.status
);
if (this.token === undefined) {
const response = await fetch(this.url + '/rest/login/' + this.username, {
method: 'POST',
headers: {'X-Graphdb-Password': this.password!},
});

if (!response.ok) {
throw Error(
'Could not authenticate username ' +
this.username +
' with GraphDB; got status code ' +
response.status
);
}

this.token = response.headers.get('Authorization')!;
}

this.token = response.headers.get('Authorization')!;

return new Headers({Authorization: this.token});
}

Expand Down

0 comments on commit 4c4b849

Please sign in to comment.