security
Auth subsystem
This module implements the authorisation/authentication subsystem of the Fractal Server. It is based on the FastAPI Users library with support for the SQLModel database adapter.
In particular, this module links the appropriate database models, sets up FastAPIUsers with Barer Token and cookie transports and register local routes. Then, for each OAuth client defined in the Fractal Settings configuration, it registers the client and the relative routes.
All routes are registerd under the auth/
prefix.
SQLModelUserDatabaseAsync
¶
Bases: Generic[UP, ID]
, BaseUserDatabase[UP, ID]
This class is from fastapi_users_db_sqlmodel Original Copyright: 2022 François Voron, released under MIT licence
Database adapter for SQLModel working purely asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_model |
Type[UP]
|
SQLModel model of a DB representation of a user. |
required |
session |
AsyncSession
|
SQLAlchemy async session. |
required |
Source code in fractal_server/app/security/__init__.py
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 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 |
|
create(create_dict)
async
¶
Create a user.
Source code in fractal_server/app/security/__init__.py
126 127 128 129 130 131 132 |
|
get(id)
async
¶
Get a single user by id.
Source code in fractal_server/app/security/__init__.py
92 93 94 |
|
get_by_email(email)
async
¶
Get a single user by email.
Source code in fractal_server/app/security/__init__.py
96 97 98 99 100 101 102 103 104 105 |
|
get_by_oauth_account(oauth, account_id)
async
¶
Get a single user by OAuth account id.
Source code in fractal_server/app/security/__init__.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
_create_first_group()
¶
Create a UserGroup
with name=FRACTAL_DEFAULT_GROUP_NAME
, if missing.
Source code in fractal_server/app/security/__init__.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
_create_first_user(email, password, is_superuser=False, is_verified=False, username=None)
async
¶
Private method to create the first fractal-server user
Create a user with the given default arguments and return a message with the relevant informations. If the user alredy exists, for example after a restart, it returns a message to inform that user already exists.
WARNING: This function is only meant to create the first user, and then
it catches and ignores IntegrityError
s (when multiple workers may be
trying to concurrently create the first user). This is not the expected
behavior for regular user creation, which must rather happen via the
/auth/register endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
email |
str
|
New user's email |
required |
password |
str
|
New user's password |
required |
is_superuser |
bool
|
|
False
|
is_verified |
bool
|
|
False
|
username |
Optional[str]
|
|
None
|
Source code in fractal_server/app/security/__init__.py
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 311 312 313 314 |
|