@@ -11,16 +11,16 @@ function newSparqlClient() {
11
11
headers : {
12
12
'mu-session-id' : httpContext . get ( 'request' ) . get ( 'mu-session-id' ) ,
13
13
'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
15
15
}
16
16
}
17
17
} ;
18
18
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 ;
22
22
23
- console . log ( `Add options on SparqlClient : ${ JSON . stringify ( options ) } ` ) ;
23
+ console . log ( `Headers set on SPARQL client : ${ JSON . stringify ( options ) } ` ) ;
24
24
25
25
return new SparqlClient ( process . env . MU_SPARQL_ENDPOINT , options ) . register ( {
26
26
mu : 'http://mu.semte.ch/vocabularies/' ,
@@ -33,13 +33,25 @@ function newSparqlClient() {
33
33
function query ( queryString ) {
34
34
console . log ( queryString ) ;
35
35
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 } ` ) ;
40
52
} 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' ) ;
43
55
}
44
56
45
57
function maybeParseJSON ( body ) {
0 commit comments