-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
BearerAuth
object to authenticate request
Simply extracting version numbers
- Loading branch information
1 parent
4b99f05
commit fa5ee1d
Showing
12 changed files
with
124 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "2.3" | ||
version = "2.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# noinspection PyUnresolvedReferences | ||
"""Module to set up bearer authentication. | ||
>>> AuthBearer | ||
""" | ||
|
||
from requests.auth import AuthBase | ||
from requests.models import PreparedRequest | ||
|
||
|
||
class BearerAuth(AuthBase): | ||
"""Instantiates ``BearerAuth`` object. | ||
>>> BearerAuth | ||
References: | ||
`New Forms of Authentication <https://requests.readthedocs.io/en/latest/user/authentication/#new | ||
-forms-of-authentication>`__ | ||
""" | ||
|
||
def __init__(self, token: str): | ||
"""Initializes the class and assign object members. | ||
Args: | ||
token: Token for bearer auth. | ||
""" | ||
self.token = token | ||
|
||
def __call__(self, request: PreparedRequest) -> PreparedRequest: | ||
"""Override built-in. | ||
Args: | ||
request: Takes prepared request as an argument. | ||
Returns: | ||
PreparedRequest: | ||
Returns the request after adding the auth header. | ||
""" | ||
request.headers["authorization"] = "Bearer " + self.token | ||
return request |
Oops, something went wrong.