@@ -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 ) ;
0 commit comments