Commits

Art Lowel authored 06de559974c
Retrieve the XSRF token first, and set it as both the XSRF header and cookie
No tags

src/app/core/auth/auth-request.service.ts

Modified
93 93 take(1)
94 94 ).subscribe((request: GetRequest) => {
95 95 this.requestService.send(request);
96 96 });
97 97
98 98 return endpoint$.pipe(
99 99 switchMap(() => this.fetchRequest(requestId, ...linksToFollow)),
100 100 );
101 101 }
102 102 /**
103 - * Factory function to create the request object to send. This needs to be a POST client side and
104 - * a GET server side. Due to CSRF validation, the server isn't allowed to send a POST, so we allow
105 - * only the server IP to send a GET to this endpoint.
103 + * Factory function to create the request object to send.
106 104 *
107 105 * @param href The href to send the request to
108 106 * @protected
109 107 */
110 - protected abstract createShortLivedTokenRequest(href: string): GetRequest | PostRequest;
108 + protected abstract createShortLivedTokenRequest(href: string): Observable<PostRequest>;
111 109
112 110 /**
113 111 * Send a request to retrieve a short-lived token which provides download access of restricted files
114 112 */
115 113 public getShortlivedToken(): Observable<string> {
116 114 return this.halService.getEndpoint(this.linkName).pipe(
117 115 filter((href: string) => isNotEmpty(href)),
118 116 distinctUntilChanged(),
119 117 map((href: string) => new URLCombiner(href, this.shortlivedtokensEndpoint).toString()),
120 - map((endpointURL: string) => this.createShortLivedTokenRequest(endpointURL)),
118 + switchMap((endpointURL: string) => this.createShortLivedTokenRequest(endpointURL)),
121 119 tap((request: RestRequest) => this.requestService.send(request)),
122 120 switchMap((request: RestRequest) => this.rdbService.buildFromRequestUUID<ShortLivedToken>(request.uuid)),
123 121 getFirstCompletedRemoteData(),
124 122 map((response: RemoteData<ShortLivedToken>) => {
125 123 if (response.hasSucceeded) {
126 124 return response.payload.value;
127 125 } else {
128 126 return null;
129 127 }
130 128 })

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut