Skip to content

Commit

Permalink
FIX: added bearer to http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arne Vandoorslaer committed Nov 4, 2020
1 parent 8297662 commit 6737054
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,13 @@ export class DGTConnectionRemoteService extends DGTConnectionService {
throw new DGTErrorArgument('Argument sourceId should be set.', sourceId);
}

return this.http.post<any>(
`${this.config.get(c => c.server.uri)}invite/${inviteId}/link/${sourceId}`, {}
).pipe(
map(res => {
if (res.status === 201) {
return res.data;
} else {
this.logger.debug(DGTConnectionRemoteService.name, 'Response status is ', res.status);
return null;
}
}),
);
return of({ sourceId, inviteId })
.pipe(
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}invite/${data.inviteId}/link/${data.sourceId}` })),
switchMap(data => this.store.select(state => state.app.accessToken).pipe(map(accessToken => ({ ...data, accessToken })))),
switchMap(data => this.http.post<any>(data.uri, '', { Authorization: `Bearer ${data.accessToken}` })),
map(res => res.data)
);
}

public sendTokensForInvite(inviteId: string, fragment: string): Observable<DGTConnection<any>> {
Expand All @@ -111,11 +106,12 @@ export class DGTConnectionRemoteService extends DGTConnectionService {

const headers = { 'Content-Type': 'application/json' };

return this.http.post<DGTConnection<any>>(
`${this.config.get(c => c.server.uri)}invite/${inviteId}/connection`, body, headers
).pipe(
map(response => response.data),
tap(connection => this.logger.debug(DGTConnectionRemoteService.name, 'Sent tokens', connection))
);
return of({ inviteId, body, headers })
.pipe(
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}invite/${data.inviteId}/connection` })),
switchMap(data => this.store.select(state => state.app.accessToken).pipe(map(accessToken => ({ ...data, accessToken })))),
switchMap(data => this.http.post<DGTConnection<any>>(data.uri, body, { Authorization: `Bearer ${data.accessToken}`, 'Content-Type': 'application/json' })),
map(res => res.data)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { DGTInvite, DGTInviteService, DGTConfigurationBaseWeb } from '@digita-ai/dgt-shared-data';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { DGTHttpService, DGTLoggerService, DGTErrorArgument, DGTConfigurationService } from '@digita-ai/dgt-shared-utils';
import { map, tap } from 'rxjs/operators';
import { map, switchMap, tap } from 'rxjs/operators';
import { DGTStateStoreService } from '../../state/services/dgt-state-store.service';
import { DGTBaseRootState } from '../../state/models/dgt-base-root-state.model';
import { DGTBaseAppState } from '../../state/models/dgt-base-app-state.model';

@Injectable()
export class DGTInviteRemoteService extends DGTInviteService {
constructor(
private http: DGTHttpService,
private logger: DGTLoggerService,
private config: DGTConfigurationService<DGTConfigurationBaseWeb>
private config: DGTConfigurationService<DGTConfigurationBaseWeb>,
public store: DGTStateStoreService<DGTBaseRootState<DGTBaseAppState>>,
) {
super();
}
Expand All @@ -19,16 +23,13 @@ export class DGTInviteRemoteService extends DGTInviteService {
throw new DGTErrorArgument('Argument inviteId should be set.', id);
}

return this.http.get<DGTInvite>(`${this.config.get(c => c.server.uri)}invite/${id}`).pipe(
map(res => {
if (res.status === 200) {
return res.data;
} else {
this.logger.debug(DGTInviteRemoteService.name, 'Response status is ', res.status);
return null;
}
}),
);
return of({ id })
.pipe(
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}invite/${data.id}` })),
switchMap(data => this.store.select(state => state.app.accessToken).pipe(map(accessToken => ({ ...data, accessToken })))),
switchMap(data => this.http.get<DGTInvite>(data.uri, { Authorization: `Bearer ${data.accessToken}` })),
map(response => response.data),
);
}
query(filter: Partial<DGTInvite>): Observable<DGTInvite[]> {
throw new Error('Method not implemented.');
Expand All @@ -47,9 +48,13 @@ export class DGTInviteRemoteService extends DGTInviteService {
throw new DGTErrorArgument('Argument inviteId should be set.', inviteId);
}

return this.http.get<DGTInvite>(`${this.config.get(c => c.server.uri)}invite/${inviteId}/verify`).pipe(
map(res => res.data),
tap(invite => this.logger.debug(DGTInviteRemoteService.name, 'Verified invite', invite))
return of({ inviteId })
.pipe(
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}invite/${data.inviteId}/verify` })),
switchMap(data => this.store.select(state => state.app.accessToken).pipe(map(accessToken => ({ ...data, accessToken })))),
switchMap(data => this.http.get<DGTInvite>(data.uri, { Authorization: `Bearer ${data.accessToken}` })),
tap(invite => this.logger.debug(DGTInviteRemoteService.name, 'Verified invite', invite)),
map(response => response.data),
);
}
}

0 comments on commit 6737054

Please sign in to comment.