Skip to content

Commit 7b0205c

Browse files
atarix83vins01-4science
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2329 (pull request DSpace#3175)
Task/dspace cris 2023 02 x/DSC-2329 Approved-by: Vincenzo Mecca
2 parents 021c835 + efff672 commit 7b0205c

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/app/bitstream-page/bitstream-download-redirect.guard.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const bitstreamDownloadRedirectGuard: CanActivateFn = (
3535
): Observable<UrlTree | boolean> => {
3636

3737
const bitstreamId = route.params.id;
38+
const accessToken: string = route.queryParams.accessToken;
3839

3940
return bitstreamDataService.findById(bitstreamId, true, false, ...BITSTREAM_PAGE_LINKS_TO_FOLLOW).pipe(
4041
getFirstCompletedRemoteData(),
@@ -67,14 +68,21 @@ export const bitstreamDownloadRedirectGuard: CanActivateFn = (
6768
if (isAuthorized && isLoggedIn && isNotEmpty(fileLink)) {
6869
hardRedirectService.redirect(fileLink);
6970
return false;
70-
} else if (isAuthorized && !isLoggedIn) {
71+
} else if (isAuthorized && !isLoggedIn && !hasValue(accessToken)) {
7172
hardRedirectService.redirect(bitstream._links.content.href);
7273
return false;
73-
} else if (!isAuthorized && isLoggedIn) {
74-
return router.createUrlTree([getForbiddenRoute()]);
75-
} else if (!isAuthorized && !isLoggedIn) {
76-
auth.setRedirectUrl(router.url);
77-
return router.createUrlTree(['login']);
74+
} else if (!isAuthorized) {
75+
// Either we have an access token, or we are logged in, or we are not logged in.
76+
// For now, the access token does not care if we are logged in or not.
77+
if (hasValue(accessToken)) {
78+
hardRedirectService.redirect(bitstream._links.content.href + '?accessToken=' + accessToken);
79+
return false;
80+
} else if (isLoggedIn) {
81+
return router.createUrlTree([getForbiddenRoute()]);
82+
} else if (!isLoggedIn) {
83+
auth.setRedirectUrl(router.url);
84+
return router.createUrlTree(['login']);
85+
}
7886
}
7987
})
8088
);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { map } from 'rxjs/operators';
1818
import { Observable } from 'rxjs';
1919
import { XSRFService } from '../xsrf/xsrf.service';
20+
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
2021

2122
/**
2223
* Server side version of the service to send authentication requests
@@ -41,8 +42,8 @@ export class ServerAuthRequestService extends AuthRequestService {
4142
* @protected
4243
*/
4344
protected createShortLivedTokenRequest(href: string): Observable<PostRequest> {
44-
// First do a call to the root endpoint in order to get an XSRF token
45-
return this.httpClient.get(this.halService.getRootHref(), { observe: 'response' }).pipe(
45+
// First do a call to the csrf endpoint in order to get an XSRF token
46+
return this.httpClient.get(new RESTURLCombiner('/security/csrf').toString(), { observe: 'response' }).pipe(
4647
// retrieve the XSRF token from the response header
4748
map((response: HttpResponse<any>) => response.headers.get(XSRF_RESPONSE_HEADER)),
4849
map((xsrfToken: string) => {

0 commit comments

Comments
 (0)