scholar_auth API Documentation
authorization
Created on 2024-10-20
@author: wf
moved from snapquery/authorization.py
Authorization
Authorization check.
Source code in scholar_auth/authorization.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
check_right_by_orcid(orcid, rights=None)
Check if the user with the given ORCID has rights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orcid
|
str
|
the ORCID iD of the user |
required |
rights
|
Optional[str]
|
the specific right to check, if None any known user passes |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the user is known and has the given right |
Source code in scholar_auth/authorization.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
default_yaml_path()
classmethod
get the default path of the user rights file
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
~/.solutions/scholar_auth/userrights.yaml |
Source code in scholar_auth/authorization.py
44 45 46 47 48 49 50 51 52 53 | |
load(yaml_path=None)
classmethod
Load user rights from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_path
|
Optional[str]
|
the path of the user rights file, default: see default_yaml_path |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Authorization |
Authorization
|
the loaded user rights, without any rights if the file does not exist |
Source code in scholar_auth/authorization.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
UserRights
the rights of a single user
Source code in scholar_auth/authorization.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
get_rights()
get the single rights of this user
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: the rights, separated by blanks or commas in the rights string |
Source code in scholar_auth/authorization.py
25 26 27 28 29 30 31 32 33 | |
nicegui_login
Created on 2026-09-30
@author: wf
ORCID login for nicegui applications - needs the optional nicegui dependency
NiceGuiScholarLogin
Bases: ScholarLogin
ORCID login that keeps the session in the nicegui user storage and serves the ORCID callback and the logout
Source code in scholar_auth/nicegui_login.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
__init__(base_path, callback_path='/orcid_callback', logout_path='/logout', home_path='/', config_file_name='orcid_config.yaml', rights_file_name='userrights.yaml')
constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
Path
|
the directory of the system with the ORCID configuration and the user rights file |
required |
callback_path
|
str
|
the path of the redirect uri registered at ORCID |
'/orcid_callback'
|
logout_path
|
str
|
the path that logs the user out |
'/logout'
|
home_path
|
str
|
the path to go to after login and logout |
'/'
|
config_file_name
|
str
|
the name of the ORCID configuration file |
'orcid_config.yaml'
|
rights_file_name
|
str
|
the name of the user rights file |
'userrights.yaml'
|
Source code in scholar_auth/nicegui_login.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
get_user_storage()
get the nicegui storage of the current user session
Returns:
| Name | Type | Description |
|---|---|---|
MutableMapping |
MutableMapping
|
app.storage.user |
Source code in scholar_auth/nicegui_login.py
55 56 57 58 59 60 61 62 63 | |
handle_callback(code)
handle the redirect from ORCID
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
the authorization code |
required |
Returns:
| Name | Type | Description |
|---|---|---|
RedirectResponse |
RedirectResponse
|
the redirect to the home path |
Raises:
| Type | Description |
|---|---|
HTTPException
|
401 if the login fails |
Source code in scholar_auth/nicegui_login.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
handle_logout()
logout the user of the current session
Returns:
| Name | Type | Description |
|---|---|---|
RedirectResponse |
RedirectResponse
|
the redirect to the home path |
Source code in scholar_auth/nicegui_login.py
85 86 87 88 89 90 91 92 93 94 | |
register_routes()
register the ORCID callback and the logout route with the nicegui app
Source code in scholar_auth/nicegui_login.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
orcid
Created on 2026-09-30
@author: wf
ORCID OAuth login - moved from snapquery/orcid.py and made independent of the web framework
OrcidAccessToken
orcid access token response
Source code in scholar_auth/orcid.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
get_samples()
classmethod
get sample access tokens
Returns:
| Type | Description |
|---|---|
list[OrcidAccessToken]
|
list[OrcidAccessToken]: the samples |
Source code in scholar_auth/orcid.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
is_valid()
check whether this access token has not expired yet
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the token is still valid |
Source code in scholar_auth/orcid.py
113 114 115 116 117 118 119 120 121 122 | |
OrcidAuth
authenticate with orcid
the session storage is supplied by the calling application as a function returning the mapping that belongs to the current user session
Source code in scholar_auth/orcid.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
__init__(base_path=None, config_file_name='orcid_config.yaml', storage_provider=None)
constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
Optional[Path]
|
the directory of the configuration file, default: ~/.solutions/scholar_auth |
None
|
config_file_name
|
str
|
the name of the configuration file |
'orcid_config.yaml'
|
storage_provider
|
Optional[Callable[[], MutableMapping]]
|
function returning the storage of the current user session, default: a single in-memory storage |
None
|
Source code in scholar_auth/orcid.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
authenticate_url()
get the url that starts the login at ORCID
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
the authorize url |
Source code in scholar_auth/orcid.py
218 219 220 221 222 223 224 225 226 | |
authenticated()
check whether the user of the current session is logged in
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if there is a valid access token for the current session |
Source code in scholar_auth/orcid.py
228 229 230 231 232 233 234 235 236 237 238 239 240 | |
available()
check whether the ORCID login is configured
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if a configuration has been loaded |
Source code in scholar_auth/orcid.py
190 191 192 193 194 195 196 197 198 | |
config_exists()
check whether the configuration file exists
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the configuration file exists |
Source code in scholar_auth/orcid.py
180 181 182 183 184 185 186 187 188 | |
get_cached_user_access_token()
get the access token of the current session
Returns:
| Type | Description |
|---|---|
Optional[OrcidAccessToken]
|
Optional[OrcidAccessToken]: the access token or None if the user is not logged in |
Source code in scholar_auth/orcid.py
242 243 244 245 246 247 248 249 250 251 252 253 | |
get_config_path()
get the path of the configuration file
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
the configuration file path |
Source code in scholar_auth/orcid.py
170 171 172 173 174 175 176 177 178 | |
get_memory_storage()
get the in-memory storage used when the application supplies none
Returns:
| Name | Type | Description |
|---|---|---|
MutableMapping |
MutableMapping
|
the in-memory storage |
Source code in scholar_auth/orcid.py
160 161 162 163 164 165 166 167 168 | |
load_config()
load the configuration
Returns:
| Type | Description |
|---|---|
Optional[OrcidConfig]
|
Optional[OrcidConfig]: the configuration or None if there is no configuration file |
Source code in scholar_auth/orcid.py
200 201 202 203 204 205 206 207 208 209 210 | |
login(access_code)
login with the code that ORCID handed to the callback
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_code
|
str
|
the authorization code |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the login succeeded |
Raises:
| Type | Description |
|---|---|
RequestException
|
if the token request fails |
Source code in scholar_auth/orcid.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
logout()
logout the user of the current session by deleting the cached access token
Source code in scholar_auth/orcid.py
306 307 308 309 310 | |
store_config()
store the configuration
Source code in scholar_auth/orcid.py
212 213 214 215 216 | |
OrcidConfig
orcid authentication configuration
Source code in scholar_auth/orcid.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
authenticate_url()
get the url that starts the login at ORCID
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
the authorize url for the authorization code flow |
Source code in scholar_auth/orcid.py
62 63 64 65 66 67 68 69 70 71 72 73 | |
get_samples()
classmethod
get sample configurations
Returns:
| Type | Description |
|---|---|
list[OrcidConfig]
|
list[OrcidConfig]: the samples |
Source code in scholar_auth/orcid.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
current_timestamp()
get the current time
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
the current time in seconds since the epoch |
Source code in scholar_auth/orcid.py
18 19 20 21 22 23 24 25 26 | |
scholar_login
Created on 2026-09-30
@author: wf
login and rights of a scholar for one system
ScholarLogin
ORCID login combined with the user rights of one system
a system keeps its ORCID configuration and its user rights file in its own directory
Source code in scholar_auth/scholar_login.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
__init__(base_path, storage_provider=None, config_file_name='orcid_config.yaml', rights_file_name='userrights.yaml')
constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
Path
|
the directory of the system with the ORCID configuration and the user rights file |
required |
storage_provider
|
Optional[Callable[[], MutableMapping]]
|
function returning the storage of the current user session |
None
|
config_file_name
|
str
|
the name of the ORCID configuration file |
'orcid_config.yaml'
|
rights_file_name
|
str
|
the name of the user rights file |
'userrights.yaml'
|
Source code in scholar_auth/scholar_login.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
authenticated()
check whether the user of the current session is logged in
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the user is logged in |
Source code in scholar_auth/scholar_login.py
85 86 87 88 89 90 91 92 93 | |
available()
check whether the ORCID login is configured for this system
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if there is an ORCID configuration |
Source code in scholar_auth/scholar_login.py
44 45 46 47 48 49 50 51 52 | |
current_user()
get the logged in user of the current session
Returns:
| Type | Description |
|---|---|
Optional[OrcidAccessToken]
|
Optional[OrcidAccessToken]: the access token with name and ORCID iD or None if nobody is logged in |
Source code in scholar_auth/scholar_login.py
95 96 97 98 99 100 101 102 103 104 105 | |
has_right(right)
check whether the user of the current session is logged in and has the given right
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
right
|
str
|
the name of the right |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the user is logged in and the user rights file grants the right |
Source code in scholar_auth/scholar_login.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
login(access_code)
login with the code that ORCID handed to the callback
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_code
|
str
|
the authorization code |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the login succeeded |
Source code in scholar_auth/scholar_login.py
66 67 68 69 70 71 72 73 74 75 76 77 | |
login_url()
get the url that starts the login at ORCID
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Optional[str]: the url or None if the ORCID login is not configured |
Source code in scholar_auth/scholar_login.py
54 55 56 57 58 59 60 61 62 63 64 | |
logout()
logout the user of the current session
Source code in scholar_auth/scholar_login.py
79 80 81 82 83 | |
user_description()
describe the logged in user of the current session
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Optional[str]: name and ORCID iD or None if nobody is logged in |
Source code in scholar_auth/scholar_login.py
123 124 125 126 127 128 129 130 131 132 133 134 | |