2
2
import recastconfig
3
3
import json
4
4
import os
5
+ import logging
5
6
import importlib
6
7
import pkg_resources
7
8
import yaml
16
17
from recastdb .database import db
17
18
18
19
20
+ log = logging .getLogger (__name__ )
21
+
19
22
def get_blueprint (name ):
20
23
module , attr = name .split (':' )
21
24
blueprintmodule = importlib .import_module (module )
@@ -70,6 +73,29 @@ def user_data(access_token):
70
73
return r .json ()
71
74
72
75
76
+ def extract_user_info (userdata ):
77
+ userjson = {'experiment' : 'unaffiliated' }
78
+
79
+ egroup_to_expt = {
80
+ 'cms-members' : 'CMS' ,
81
+ 'alice-member' : 'ALICE' ,
82
+ 'atlas-active-members-all' : 'ATLAS' ,
83
+ 'lhcb-general' : 'LHCb'
84
+ }
85
+
86
+ for x in userdata :
87
+ if x ['Type' ] == 'http://schemas.xmlsoap.org/claims/Firstname' :
88
+ userjson ['firstname' ] = x ['Value' ]
89
+ if x ['Type' ] == 'http://schemas.xmlsoap.org/claims/Lastname"' :
90
+ userjson ['lastname' ] = x ['Value' ]
91
+ if x ['Type' ] == 'http://schemas.xmlsoap.org/claims/CommonName' :
92
+ userjson ['username' ] = x ['Value' ]
93
+ if x ['Type' ] == 'http://schemas.xmlsoap.org/claims/Group' :
94
+ if x ['Value' ] in egroup_to_expt :
95
+ userjson ['experiment' ] = egroup_to_expt [x ['Value' ]]
96
+ return userjson
97
+
98
+
73
99
@flask_app .route (recastconfig .config ['RECAST_OAUTH_REDIRECT_ROUTE' ])
74
100
@oauth_app .authorized_handler
75
101
def oauth_redirect (resp ):
@@ -78,23 +104,14 @@ def oauth_redirect(resp):
78
104
return redirect (next_url )
79
105
80
106
data = user_data (resp ['access_token' ])
81
- session ['user' ] = {}
82
-
83
- for x in data :
84
- if x ['Type' ] == 'http://schemas.xmlsoap.org/claims/Firstname' :
85
- session ['user' ]['firstname' ] = x ['Value' ]
86
- if x ['Type' ] == 'http://schemas.xmlsoap.org/claims/Lastname"' :
87
- session ['user' ]['lastname' ] = x ['Value' ]
88
- if x ['Type' ] == 'http://schemas.xmlsoap.org/claims/CommonName' :
89
- session ['user' ]['username' ] = x ['Value' ]
107
+ session ['user' ] = extract_user_info (data )
90
108
91
109
return redirect (next_url )
92
110
93
111
94
112
@flask_app .route ('/login' )
95
113
def login ():
96
- redirect_uri = recastconfig .config [
97
- 'RECAST_BASEURL' ] + url_for ('oauth_redirect' )
114
+ redirect_uri = recastconfig .config ['RECAST_BASEURL' ] + url_for ('oauth_redirect' )
98
115
return oauth_app .authorize (callback = redirect_uri )
99
116
100
117
0 commit comments