authorization
mlte/backend/api/auth/authorization.py
Setup of OAuth based authorization checks.
AuthorizedUser = Annotated[BasicUser, Depends(get_authorized_user)]
module-attribute
Type alias to simplify use of get user.
oauth2_scheme = OAuth2PasswordBearer(tokenUrl=f'{settings.API_PREFIX}{TOKEN_ENDPOINT_URL}')
module-attribute
Securty scheme to be used.
get_authorized_user(token, resource)
async
Given a token, gets the authenticated user and checks if it has access to resources.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
A JWT bearer access token with user information. |
required |
resource
|
Annotated[Permission, Depends(get_current_resource)]
|
A ResourceAction object indicating the resource and actions we are checking for. |
required |
Returns:
Type | Description |
---|---|
BasicUser
|
A User data structure, with a User that has access to the resources. |
Source code in mlte/backend/api/auth/authorization.py
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 |
|
get_current_resource(request)
async
Gets a resource permission description for the current resource, method and model.
Source code in mlte/backend/api/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 |
|
get_username_from_token(token, key)
Obtains a user from an encoded token, if the token is valid.
Source code in mlte/backend/api/auth/authorization.py
81 82 83 84 85 |
|
is_authorized(current_user, resource)
Checks if the current user is authorized to access the current resource.
Source code in mlte/backend/api/auth/authorization.py
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 |
|