@@ -31,7 +31,7 @@ const keycloak = new Keycloak({
3131} ) ;
3232const YOUR_APP_SCOPES = "team email profile" ; // full list at https://iam.ebrains.eu/auth/realms/hbp/.well-known/openid-configuration
3333
34- export default function initAuth ( main ) {
34+ function initAuth ( main ) {
3535 console . log ( "DOM content is loaded, initialising Keycloak client..." ) ;
3636 keycloak
3737 . init ( { flow : "implicit" } )
@@ -129,3 +129,40 @@ function verifyMessage(event) {
129129 // Login otherwise
130130 return login ( YOUR_APP_SCOPES ) ;
131131}
132+
133+ function checkPermissions ( auth ) {
134+ const config = {
135+ headers : {
136+ Authorization : "Bearer " + auth . token ,
137+ } ,
138+ } ;
139+
140+ const corsProxyUrl = "https://corsproxy.apps.tc.humanbrainproject.eu/" ;
141+ const userInfoUrl =
142+ corsProxyUrl +
143+ "https://iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/userinfo" ;
144+ return fetch ( userInfoUrl , config )
145+ . then ( response => response . json ( ) )
146+ . then ( ( userInfo ) => {
147+ //return auth.loadUserInfo().then((userInfo) => {
148+
149+
150+ console . log ( userInfo ) ;
151+ if (
152+ userInfo . roles . group . includes (
153+ "group-dataset-curators"
154+ ) &&
155+ userInfo . roles . group . includes (
156+ "group-in-depth-curators"
157+ )
158+ ) {
159+ console . log ( "User is a curator" ) ;
160+ auth . isCurator = true ;
161+ } else {
162+ console . log ( "User is not a curator" ) ;
163+ auth . isCurator = false ;
164+ }
165+ } ) ;
166+ }
167+
168+ export { initAuth , checkPermissions }
0 commit comments