@@ -11,16 +11,16 @@ function newSparqlClient() {
1111 headers : {
1212 'mu-session-id' : httpContext . get ( 'request' ) . get ( 'mu-session-id' ) ,
1313 'mu-call-id' : httpContext . get ( 'request' ) . get ( 'mu-call-id' ) ,
14- 'mu-authorization- groups' : httpContext . get ( 'request' ) . get ( 'mu-authorization- groups' )
14+ 'mu-auth-allowed- groups' : httpContext . get ( 'request' ) . get ( 'mu-auth-allowed- groups' ) // groups of incoming request
1515 }
1616 }
1717 } ;
1818
19- const authorizationGroups = httpContext . get ( 'response' ) . get ( 'mu-authorization- groups' ) ;
20- if ( authorizationGroups )
21- options . requestDefaults . headers [ 'mu-authorization- groups' ] = authorizationGroups ;
19+ const allowedGroups = httpContext . get ( 'response' ) . get ( 'mu-auth-allowed- groups' ) ; // groups returned by a previous SPARQL query
20+ if ( allowedGroups )
21+ options . requestDefaults . headers [ 'mu-auth-allowed- groups' ] = allowedGroups ;
2222
23- console . log ( `Add options on SparqlClient : ${ JSON . stringify ( options ) } ` ) ;
23+ console . log ( `Headers set on SPARQL client : ${ JSON . stringify ( options ) } ` ) ;
2424
2525 return new SparqlClient ( process . env . MU_SPARQL_ENDPOINT , options ) . register ( {
2626 mu : 'http://mu.semte.ch/vocabularies/' ,
@@ -33,13 +33,25 @@ function newSparqlClient() {
3333function query ( queryString ) {
3434 console . log ( queryString ) ;
3535 return newSparqlClient ( ) . query ( queryString ) . executeRaw ( ) . then ( response => {
36- const authorizationGroups = response . headers [ 'mu-authorization-groups' ] ;
37- if ( authorizationGroups ) {
38- httpContext . get ( 'response' ) . setHeader ( 'mu-authorization-groups' , authorizationGroups ) ;
39- console . log ( `Set mu-authorization-groups header to ${ authorizationGroups } ` ) ;
36+
37+ // set mu-auth-allowed-groups on outgoing response
38+ const allowedGroups = response . headers [ 'mu-auth-allowed-groups' ] ;
39+ if ( allowedGroups ) {
40+ httpContext . get ( 'response' ) . setHeader ( 'mu-auth-allowed-groups' , allowedGroups ) ;
41+ console . log ( `Update mu-auth-allowed-groups to ${ allowedGroups } ` ) ;
42+ } else {
43+ httpContext . get ( 'response' ) . removeHeader ( 'mu-auth-allowed-groups' ) ;
44+ console . log ( 'Remove mu-auth-allowed-groups' ) ;
45+ }
46+
47+ // set mu-auth-used-groups on outgoing response
48+ const usedGroups = response . headers [ 'mu-auth-used-groups' ] ;
49+ if ( usedGroups ) {
50+ httpContext . get ( 'response' ) . setHeader ( 'mu-auth-used-groups' , usedGroups ) ;
51+ console . log ( `Update mu-auth-used-groups to ${ usedGroups } ` ) ;
4052 } else {
41- httpContext . get ( 'response' ) . removeHeader ( 'mu-authorization -groups' ) ;
42- console . log ( 'Remove mu-authorization- groups header ' ) ;
53+ httpContext . get ( 'response' ) . removeHeader ( 'mu-auth-used -groups' ) ;
54+ console . log ( 'Remove mu-auth-used- groups' ) ;
4355 }
4456
4557 function maybeParseJSON ( body ) {
0 commit comments