FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
stackit-sdk-python/examples/core/custom_auth.py at main · stackitcloud/stackit-sdk-python · GitHub
stackitcloud
/
stackit-sdk-python
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
57
Code
Issues
4
Pull requests
274
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
stackit-sdk-python
/
examples
/
core
/
custom_auth.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (19 loc) · 781 Bytes
Breadcrumbs
stackit-sdk-python
/
examples
/
core
/
custom_auth.py
Copy path
File metadata and controls
26 lines (19 loc) · 781 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import
jwt
from
requests
import
Request
from
requests
.
auth
import
AuthBase
from
stackit
.
core
.
configuration
import
Configuration
"""
You can create your own authorization class to implement your own authorization logic.
You need to derive from the class 'AuthBase' to implement your own class.
"""
class
MyAuth
(
AuthBase
):
__access_token
:
str
def
__init__
(
self
,
key
:
str
):
self
.
__access_token
=
jwt
.
encode
({
"some"
:
"payload"
},
key
,
algorithm
=
"HS256"
)
def
__call__
(
self
,
request
:
Request
)
->
Request
:
request
.
headers
[
"Authorization"
]
=
f"Bearer
{
self
.
__access_token
}
"
return
request
# Initialize custom auth method
auth_method
=
MyAuth
(
key
=
"my_super_secret_key"
)
# Set it in the configuration
config
=
Configuration
(
custom_auth
=
auth_method
)
Back
|
FazBrowse Home
|
New Git URL