@@ -11,6 +11,7 @@ import {
1111} from '@angular/core' ;
1212import {
1313 ActivatedRoute ,
14+ Params ,
1415 Router ,
1516} from '@angular/router' ;
1617import { TranslateModule } from '@ngx-translate/core' ;
@@ -83,6 +84,10 @@ export class BitstreamDownloadPageComponent implements OnInit {
8384 }
8485
8586 ngOnInit ( ) : void {
87+ const accessToken$ : Observable < string > = this . route . queryParams . pipe (
88+ map ( ( queryParams : Params ) => queryParams ?. accessToken || null ) ,
89+ take ( 1 ) ,
90+ ) ;
8691
8792 this . bitstreamRD$ = this . route . data . pipe (
8893 map ( ( data ) => data . bitstream ) ) ;
@@ -96,32 +101,40 @@ export class BitstreamDownloadPageComponent implements OnInit {
96101 switchMap ( ( bitstream : Bitstream ) => {
97102 const isAuthorized$ = this . authorizationService . isAuthorized ( FeatureID . CanDownload , isNotEmpty ( bitstream ) ? bitstream . self : undefined ) ;
98103 const isLoggedIn$ = this . auth . isAuthenticated ( ) ;
99- return observableCombineLatest ( [ isAuthorized$ , isLoggedIn$ , observableOf ( bitstream ) ] ) ;
104+ return observableCombineLatest ( [ isAuthorized$ , isLoggedIn$ , accessToken$ , observableOf ( bitstream ) ] ) ;
100105 } ) ,
101- filter ( ( [ isAuthorized , isLoggedIn , bitstream ] : [ boolean , boolean , Bitstream ] ) => hasValue ( isAuthorized ) && hasValue ( isLoggedIn ) ) ,
106+ filter ( ( [ isAuthorized , isLoggedIn , accessToken , bitstream ] : [ boolean , boolean , string , Bitstream ] ) => ( hasValue ( isAuthorized ) && hasValue ( isLoggedIn ) ) || hasValue ( accessToken ) ) ,
102107 take ( 1 ) ,
103- switchMap ( ( [ isAuthorized , isLoggedIn , bitstream ] : [ boolean , boolean , Bitstream ] ) => {
108+ switchMap ( ( [ isAuthorized , isLoggedIn , accessToken , bitstream ] : [ boolean , boolean , string , Bitstream ] ) => {
104109 if ( isAuthorized && isLoggedIn ) {
105110 return this . fileService . retrieveFileDownloadLink ( bitstream . _links . content . href ) . pipe (
106111 filter ( ( fileLink ) => hasValue ( fileLink ) ) ,
107112 take ( 1 ) ,
108113 map ( ( fileLink ) => {
109114 return [ isAuthorized , isLoggedIn , bitstream , fileLink ] ;
110115 } ) ) ;
116+ } else if ( hasValue ( accessToken ) ) {
117+ return [ [ isAuthorized , ! isLoggedIn , bitstream , '' , accessToken ] ] ;
111118 } else {
112119 return [ [ isAuthorized , isLoggedIn , bitstream , '' ] ] ;
113120 }
114121 } ) ,
115- ) . subscribe ( ( [ isAuthorized , isLoggedIn , bitstream , fileLink ] : [ boolean , boolean , Bitstream , string ] ) => {
122+ ) . subscribe ( ( [ isAuthorized , isLoggedIn , bitstream , fileLink , accessToken ] : [ boolean , boolean , Bitstream , string , string ] ) => {
116123 if ( isAuthorized && isLoggedIn && isNotEmpty ( fileLink ) ) {
117124 this . hardRedirectService . redirect ( fileLink ) ;
118- } else if ( isAuthorized && ! isLoggedIn ) {
125+ } else if ( isAuthorized && ! isLoggedIn && ! hasValue ( accessToken ) ) {
119126 this . hardRedirectService . redirect ( bitstream . _links . content . href ) ;
120- } else if ( ! isAuthorized && isLoggedIn ) {
121- this . router . navigateByUrl ( getForbiddenRoute ( ) , { skipLocationChange : true } ) ;
122- } else if ( ! isAuthorized && ! isLoggedIn ) {
123- this . auth . setRedirectUrl ( this . router . url ) ;
124- this . router . navigateByUrl ( 'login' ) ;
127+ } else if ( ! isAuthorized ) {
128+ // Either we have an access token, or we are logged in, or we are not logged in.
129+ // For now, the access token does not care if we are logged in or not.
130+ if ( hasValue ( accessToken ) ) {
131+ this . hardRedirectService . redirect ( bitstream . _links . content . href + '?accessToken=' + accessToken ) ;
132+ } else if ( isLoggedIn ) {
133+ this . router . navigateByUrl ( getForbiddenRoute ( ) , { skipLocationChange : true } ) ;
134+ } else if ( ! isLoggedIn ) {
135+ this . auth . setRedirectUrl ( this . router . url ) ;
136+ this . router . navigateByUrl ( 'login' ) ;
137+ }
125138 }
126139 } ) ;
127140 }
0 commit comments