FastJWTDeps
Bases: Generic[T]
Bundle of FastJWT capabilities
Note
This class is used to access FastJWT's capabilities within
the scope of a FastAPI Request. It is accessible via the
FastJWT.BUNDLE
instance's attribute OR FastJWT.get_dependency
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_from |
FastJWT[T]
|
FastJWT instance |
required |
request |
Request
|
FastAPI Request instance. Defaults to None. |
None
|
response |
Response
|
FastAPI Response instance. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
request |
Request
|
FastAPI Request instance |
response |
Response
|
FastAPI Response instance |
_security |
FastJWT[T]
|
FastJWT instance |
Source code in fastjwt/dependencies.py
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 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 |
|
request: Request
property
The FastAPI Request instance
response: Response
property
The FastAPI Response instance
__init__(_from, request=None, response=None)
See help(FastJWTDeps) for more info
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_from |
FastJWT[T]
|
FastJWT instance |
required |
request |
Request
|
FastAPI Request instance. Defaults to None. |
None
|
response |
Response
|
FastAPI Response instance. Defaults to None. |
None
|
Source code in fastjwt/dependencies.py
create_access_token(uid, fresh=False, headers=None, expiry=None, data=None, audience=None, *args, **kwargs)
Create an access token
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uid |
str
|
Unique identifier to generate token for |
required |
fresh |
bool
|
Generate fresh token. Defaults to False. |
False
|
headers |
Dict[str, Any]
|
TODO. Defaults to None. |
None
|
expiry |
DateTimeExpression
|
User defined expiry claim. Defaults to None. |
None
|
data |
Dict[str, Any]
|
Additional data store in token. Defaults to None. |
None
|
audience |
StrOrSeq
|
Audience claim. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Access Token |
Source code in fastjwt/dependencies.py
create_refresh_token(uid, headers=None, expiry=None, data=None, audience=None, *args, **kwargs)
Generate a refresh token
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uid |
str
|
Unique identifier to generate token for |
required |
headers |
Dict[str, Any]
|
TODO. Defaults to None. |
None
|
expiry |
DateTimeExpression
|
User defined expiry claim. Defaults to None. |
None
|
data |
Dict[str, Any]
|
Additional data store in token. Defaults to None. |
None
|
audience |
StrOrSeq
|
Audience claim. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Refresh Token |
Source code in fastjwt/dependencies.py
get_current_subject()
async
Get the current subject instance
Use the request's token to retrieve the subject instance. Enforce a validation step to ensure the token is valid.
Returns:
Type | Description |
---|---|
Optional[T]
|
Optional[T]: Subject instance |
Note
This method will always return None
if
FastJWT.set_subject_getter
has not been set first.
Source code in fastjwt/dependencies.py
set_access_cookies(token, response=None, max_age=None)
Add 'Set-Cookie' for access token in response header
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Access token |
required |
response |
Response
|
Response to set cookie on. Defaults to None |
None
|
max_age |
int
|
Max Age cookie paramater. Defaults to None |
None
|
Note
When response
is not provided,
the FastJWTDeps.response
attribute is used.
Source code in fastjwt/dependencies.py
set_refresh_cookies(token, response=None, max_age=None)
Add 'Set-Cookie' for refresh token in response header
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Refresh token |
required |
response |
Response
|
Response to set cookie on. Defaults to None |
None
|
max_age |
int
|
Max Age cookie paramater. Defaults to None |
None
|
Note
When response
is not provided,
the FastJWTDeps.response
attribute is used.
Source code in fastjwt/dependencies.py
unset_access_cookies(response=None)
Remove 'Set-Cookie' for access token in response header
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
Response
|
Response to remove cooke from. Defaults to None |
None
|
Note
When response
is not provided,
the FastJWTDeps.response
attribute is used.
Source code in fastjwt/dependencies.py
unset_cookies(response=None)
Remove 'Set-Cookie' for tokens from response headers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
Response
|
Response to remove token cookies from. Defaults to None |
None
|
Note
When response
is not provided,
the FastJWTDeps.response
attribute is used.
Source code in fastjwt/dependencies.py
unset_refresh_cookies(response=None)
Remove 'Set-Cookie' for refresh token in response header
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
Response
|
Response to remove cooke from. Defaults to None |
None
|
Note
When response
is not provided,
the FastJWTDeps.response
attribute is used.