Skip to content

Commit 70a7e65

Browse files
authored
Merge pull request #2037 from numbersprotocol/feature-pass-new-jwt-to-iframe
Feature pass new jwt to iframe
2 parents a98a760 + f4b92e4 commit 70a7e65

File tree

5 files changed

+54
-12
lines changed

5 files changed

+54
-12
lines changed

src/app/features/home/details/details.page.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
"
5656
>
5757
<div class="slide">
58-
<iframe [src]="iframeUrlWithToken$ | ngrxPush"></iframe>
58+
<div *ngIf="iframeUrlWithJWTToken$ | ngrxPush as iframeUrlWithJWTToken">
59+
<iframe [src]="iframeUrlWithJWTToken"></iframe>
60+
</div>
5961
</div>
6062
</ng-template>
6163
</swiper>

src/app/features/home/details/details.page.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,22 @@ export class DetailsPage {
213213
})
214214
);
215215

216+
readonly iframeUrlWithJWTToken$ = combineLatest([
217+
this.activeDetailedCapture$,
218+
defer(() => this.diaBackendAuthService.queryJWTToken$()),
219+
]).pipe(
220+
distinctUntilChanged(),
221+
map(([detailedCapture, token]) => {
222+
const params =
223+
`nid=${detailedCapture.id}` +
224+
`&token=${token.access}` +
225+
`&refresh_token=${token.refresh}` +
226+
`&from=mycapture`;
227+
const url = `${BUBBLE_IFRAME_URL}/asset_page?${params}`;
228+
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
229+
})
230+
);
231+
216232
readonly isFromSeriesPage$ = this.type$.pipe(map(type => type === 'series'));
217233

218234
constructor(

src/app/features/home/explore-tab/explore-tab/explore-tab.component.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
</div>
77

88
<ng-template #bubbleIframe>
9-
<iframe
10-
[src]="bubbleIframeUrl$ | ngrxPush | safeResourceUrl"
11-
class="bubble-iframe"
12-
></iframe>
9+
<div
10+
*ngIf="
11+
bubbleIframeUrlWithJWTToken$ | ngrxPush as bubbleIframeUrlWithJWTToken
12+
"
13+
>
14+
<iframe
15+
[src]="bubbleIframeUrlWithJWTToken | safeResourceUrl"
16+
class="bubble-iframe"
17+
></iframe>
18+
</div>
1319
</ng-template>

src/app/features/home/explore-tab/explore-tab/explore-tab.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import { Component } from '@angular/core';
22
import { DomSanitizer } from '@angular/platform-browser';
3+
import { defer } from 'rxjs';
34
import { map } from 'rxjs/operators';
45
import { DiaBackendAuthService } from '../../../../shared/dia-backend/auth/dia-backend-auth.service';
56
import { BUBBLE_IFRAME_URL } from '../../../../shared/dia-backend/secret';
67
import { ErrorService } from '../../../../shared/error/error.service';
78
import { NetworkService } from '../../../../shared/network/network.service';
8-
import { isNonNullable } from '../../../../utils/rx-operators/rx-operators';
99

1010
@Component({
1111
selector: 'app-explore-tab',
1212
templateUrl: './explore-tab.component.html',
1313
styleUrls: ['./explore-tab.component.scss'],
1414
})
1515
export class ExploreTabComponent {
16-
readonly bubbleIframeUrl$ = this.diaBackendAuthService.token$.pipe(
17-
isNonNullable(),
18-
map(token => {
19-
return `${BUBBLE_IFRAME_URL}/?token=${token}`;
20-
})
21-
);
16+
readonly bubbleIframeUrlWithJWTToken$ = defer(() => {
17+
return this.diaBackendAuthService.queryJWTToken$().pipe(
18+
map(token => {
19+
return `${BUBBLE_IFRAME_URL}/?token=${token.access}&refresh_token=${token.refresh}`;
20+
})
21+
);
22+
});
2223

2324
readonly networkConnected$ = this.networkService.connected$;
2425

src/app/shared/dia-backend/auth/dia-backend-auth.service.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ export class DiaBackendAuthService {
128128
);
129129
}
130130

131+
queryJWTToken$() {
132+
return defer(() => this.getAuthHeaders()).pipe(
133+
concatMap(headers => {
134+
return this.httpClient.post<QueryJWTTokenResponse>(
135+
`${BASE_URL}/api/v3/auth/qjwt/`,
136+
{},
137+
{ headers }
138+
);
139+
})
140+
);
141+
}
142+
131143
private readUser$() {
132144
return defer(() => this.getAuthHeaders()).pipe(
133145
concatMap(headers =>
@@ -413,6 +425,11 @@ export interface LoginResponse {
413425
readonly auth_token: string;
414426
}
415427

428+
export interface QueryJWTTokenResponse {
429+
readonly access: string;
430+
readonly refresh: string;
431+
}
432+
416433
export interface ReadUserResponse {
417434
readonly username: string;
418435
readonly email: string;

0 commit comments

Comments
 (0)