Auth Database
Authentication and authorization database.
Database Schema
schema
Attributes
USER_CODE_LENGTH = 8
module-attribute
Base = declarative_base()
module-attribute
Classes
FlowStatus
Bases: Enum
The normal flow is PENDING -> READY -> DONE Pending is upon insertion Ready/Error is set in response to IdP Done means the user has been issued the dirac token.
Source code in diracx-db/src/diracx/db/sql/auth/schema.py
Attributes
PENDING = auto()
class-attribute
instance-attribute
READY = auto()
class-attribute
instance-attribute
DONE = auto()
class-attribute
instance-attribute
ERROR = auto()
class-attribute
instance-attribute
DeviceFlows
Bases: Base
Source code in diracx-db/src/diracx/db/sql/auth/schema.py
Attributes
user_code = Column('UserCode', String(USER_CODE_LENGTH), primary_key=True)
class-attribute
instance-attribute
status = EnumColumn('Status', FlowStatus, server_default=(FlowStatus.PENDING.name))
class-attribute
instance-attribute
creation_time = DateNowColumn('CreationTime')
class-attribute
instance-attribute
client_id = Column('ClientID', String(255))
class-attribute
instance-attribute
scope = Column('Scope', String(1024))
class-attribute
instance-attribute
device_code = Column('DeviceCode', String(128), unique=True)
class-attribute
instance-attribute
id_token = NullColumn('IDToken', JSON())
class-attribute
instance-attribute
AuthorizationFlows
Bases: Base
Source code in diracx-db/src/diracx/db/sql/auth/schema.py
Attributes
uuid = Column('UUID', Uuid(as_uuid=False), primary_key=True)
class-attribute
instance-attribute
status = EnumColumn('Status', FlowStatus, server_default=(FlowStatus.PENDING.name))
class-attribute
instance-attribute
client_id = Column('ClientID', String(255))
class-attribute
instance-attribute
creation_time = DateNowColumn('CreationTime')
class-attribute
instance-attribute
scope = Column('Scope', String(1024))
class-attribute
instance-attribute
code_challenge = Column('CodeChallenge', String(255))
class-attribute
instance-attribute
code_challenge_method = Column('CodeChallengeMethod', String(8))
class-attribute
instance-attribute
redirect_uri = Column('RedirectURI', String(255))
class-attribute
instance-attribute
code = NullColumn('Code', String(255))
class-attribute
instance-attribute
id_token = NullColumn('IDToken', JSON())
class-attribute
instance-attribute
RefreshTokenStatus
Bases: Enum
The normal flow is CREATED -> REVOKED.
Note1: There is no EXPIRED status as it can be calculated from a creation time Note2: As part of the refresh token rotation mechanism, the revoked token should be retained
Source code in diracx-db/src/diracx/db/sql/auth/schema.py
Attributes
CREATED = auto()
class-attribute
instance-attribute
REVOKED = auto()
class-attribute
instance-attribute
RefreshTokens
Bases: Base
Store attributes bound to a refresh token, as well as specific user attributes that might be then used to generate access tokens.
Source code in diracx-db/src/diracx/db/sql/auth/schema.py
Attributes
jti = Column('JTI', Uuid(as_uuid=False), primary_key=True)
class-attribute
instance-attribute
status = EnumColumn('Status', RefreshTokenStatus, server_default=(RefreshTokenStatus.CREATED.name))
class-attribute
instance-attribute
scope = Column('Scope', String(1024))
class-attribute
instance-attribute
sub = Column('Sub', String(256), index=True)
class-attribute
instance-attribute
Functions
Database Access Layer
db
Attributes
USER_CODE_ALPHABET = 'BCDFGHJKLMNPQRSTVWXZ'
module-attribute
MAX_RETRY = 5
module-attribute
logger = logging.getLogger(__name__)
module-attribute
Classes
AuthDB
Bases: BaseSQLDB
Source code in diracx-db/src/diracx/db/sql/auth/db.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 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 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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
Attributes
metadata = AuthDBBase.metadata
class-attribute
instance-attribute
Functions
post_create(conn)
async
classmethod
Create partitions if it is a MySQL DB and it does not have it yet and the table does not have any data yet. We do this as a post_create step as sqlalchemy does not support partition so well.
Source code in diracx-db/src/diracx/db/sql/auth/db.py
device_flow_validate_user_code(user_code, max_validity)
async
Validate that the user_code can be used (Pending status, not expired).
Returns the scope field for the given user_code
:raises: NoResultFound if no such user code currently Pending
Source code in diracx-db/src/diracx/db/sql/auth/db.py
get_device_flow(device_code)
async
:raises: NoResultFound
Source code in diracx-db/src/diracx/db/sql/auth/db.py
update_device_flow_status(device_code, status)
async
Source code in diracx-db/src/diracx/db/sql/auth/db.py
device_flow_insert_id_token(user_code, id_token, max_validity)
async
:raises: AuthorizationError if no such code or status not pending
Source code in diracx-db/src/diracx/db/sql/auth/db.py
insert_device_flow(client_id, scope)
async
Source code in diracx-db/src/diracx/db/sql/auth/db.py
insert_authorization_flow(client_id, scope, code_challenge, code_challenge_method, redirect_uri)
async
Source code in diracx-db/src/diracx/db/sql/auth/db.py
authorization_flow_insert_id_token(uuid, id_token, max_validity)
async
Returns code, redirect_uri :raises: AuthorizationError if no such uuid or status not pending.
Source code in diracx-db/src/diracx/db/sql/auth/db.py
get_authorization_flow(code, max_validity)
async
Get the authorization flow details based on the code.
Source code in diracx-db/src/diracx/db/sql/auth/db.py
update_authorization_flow_status(code, status)
async
Update the status of an authorization flow based on the code.
Source code in diracx-db/src/diracx/db/sql/auth/db.py
insert_refresh_token(jti, subject, scope)
async
Insert a refresh token in the DB as well as user attributes required to generate access tokens.
Source code in diracx-db/src/diracx/db/sql/auth/db.py
get_refresh_token(jti)
async
Get refresh token details bound to a given JWT ID.
Source code in diracx-db/src/diracx/db/sql/auth/db.py
get_user_refresh_tokens(subject=None)
async
Get a list of refresh token details based on a subject ID (not revoked).
Source code in diracx-db/src/diracx/db/sql/auth/db.py
revoke_refresh_token(jti)
async
Revoke a token given by its JWT ID.
Source code in diracx-db/src/diracx/db/sql/auth/db.py
revoke_user_refresh_tokens(subject)
async
Revoke all the refresh tokens belonging to a user (subject ID).