Skip to content

Commit

Permalink
fix: don't send auth header when token is null
Browse files Browse the repository at this point in the history
  • Loading branch information
wouteraj committed Nov 10, 2020
1 parent 80be746 commit c2487e4
Showing 1 changed file with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
.pipe(map(source => ({ ...data, source })))),
switchMap(data => forkJoin(Object.keys(data.groupedEntities).map(uri => this.generateToken(uri, data.connection, data.source)
.pipe(
switchMap(token => this.http.patch(
map(token => (token ? {
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
} : { 'Content-Type': 'application/sparql-update', })),
switchMap(headers => this.http.patch(
uri,
this.sparql.generateSparqlUpdate(
data.groupedEntities[uri],
'insert'
),
{
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
}
headers
)
)
))
Expand Down Expand Up @@ -104,12 +105,14 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
.pipe(map(source => ({ ...data, source })))),
tap(data => this.logger.debug(DGTSourceSolidConnector.name, 'Retrieved source', data)),
switchMap(data => this.generateToken(data.uri, data.connection, data.source)
.pipe(map(token => ({ ...data, token })))),
.pipe(map(token => ({
...data, token, headers: token ? {
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
} : { 'Content-Type': 'application/sparql-update', },
})))),
tap(data => this.logger.debug(DGTSourceSolidConnector.name, 'Generated token', data)),
switchMap(data => this.http.get<string>(data.uri, {
Authorization: 'Bearer ' + data.token,
Accept: 'text/turtle'
}, true)
switchMap(data => this.http.get<string>(data.uri, data.headers, true)
.pipe(map(response => ({ ...data, response, triples: response.data ? this.triples.createFromString(response.data, data.uri) : [] })))),
tap(data => this.logger.debug(DGTSourceSolidConnector.name, 'Request completed', data)),
switchMap(data => transformer.toDomain([{
Expand Down Expand Up @@ -162,17 +165,18 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
forkJoin(
Object.keys(data.groupedEntities).map((uri) => {
return this.generateToken(uri, data.connection, data.source).pipe(
switchMap((token) =>
map(token => (token ? {
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
} : { 'Content-Type': 'application/sparql-update', })),
switchMap((headers) =>
this.http.patch(
uri,
this.sparql.generateSparqlUpdate(
data.groupedEntities[uri],
'delete'
),
{
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
}
headers
)
)
);
Expand Down Expand Up @@ -261,15 +265,16 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
data.connection,
data.source
).pipe(
switchMap((token) => {
map(token => (token ? {
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
} : { 'Content-Type': 'application/sparql-update', })),
switchMap((headers) => {
if (update.delta.original.triples.length === 0) {
return this.http.patch(
update.delta.updated.uri,
this.sparql.generateSparqlUpdate([update.delta.updated], 'insert'),
{
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
}
headers
);
}

Expand All @@ -287,10 +292,7 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
'insertdelete',
[update.delta.original]
),
{
'Content-Type': 'application/sparql-update',
Authorization: 'Bearer ' + token,
}
headers
);
})
)
Expand Down Expand Up @@ -757,11 +759,11 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
connection: DGTConnectionSolid,
source: DGTSourceSolid
): Observable<string> {
return DGTSourceSolidToken.issueFor(
return source.state === DGTSourceState.PREPARED ? DGTSourceSolidToken.issueFor(
uri,
connection.configuration.privateKey,
source.configuration.client_id,
connection.configuration.idToken
);
) : of(null);
}
}

0 comments on commit c2487e4

Please sign in to comment.