bookops_worldcat.authorize
Provides means to authenticate and authorize interactions with OCLC web services.
WorldcatAccessToken
WorldcatAccessToken(
key: str,
secret: str,
scopes: str,
agent: str = "",
timeout: Union[
int,
float,
Tuple[int, int],
Tuple[float, float],
None,
] = (5, 5),
)
Requests a WorldCat access token.
Authenticates and authorizes using Client Credentials Grant flow. A token with correctly bonded scopes can be passed into a session of an OCLC web service to authorize requests for resources.
Example
from bookops_worldcat import WorldcatAccessToken
token = WorldcatAccessToken(
key="my_WSKey_client_id",
secret="my_WSKey_secret",
scopes="WorldCatMetadataAPI",
agent="my_app/1.0.0")
print(token.token_str)
#>"tk_Yebz4BpEp9dAsghA7KpWx6dYD1OZKWBlHjqW"
print(token.is_expired())
#>False
print(token.server_response.json())
{
"token_token": "tk_Yebz4BpEp9dAsghA7KpWx6dYD1OZKWBlHjqW",
"token_type": "bearer",
"expires_in": "1199",
"principalID": "",
"principalIDNS": "",
"scopes": "WorldCatMetadataAPI",
"contextInstitutionId": "00001",
"expires_at": "2020-08-23 18:45:29Z"
}
print(token.server_response.request.headers)
{
"User-Agent": "my_app/1.0.0",
"Accept-Encoding": "gzip, deflate",
"Accept": "application/json",
"Connection": "keep-alive",
"Content-Length": "67",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic encoded_authorization_here="
}
Usage Documentation:
PARAMETER | DESCRIPTION |
---|---|
key |
Your WSKey public client_id
TYPE:
|
secret |
Your WSKey secret
TYPE:
|
scopes |
Request scopes for the access token as a string. Multiple scopes
should be separated with a space. Users with WSKeys set up to act on
behalf of multiple institutions should provide scope and registryID
in the format:
EXAMPLES:
TYPE:
|
agent |
TYPE:
|
timeout |
How long to wait for server to send data before giving up. Accepts separate values for connect and read timeouts or a single value.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If |
ValueError
|
If an empty str is passed to |
WorldcatAuthorizationError
|
If request for token encounters any errors. |
Source code in bookops_worldcat\authorize.py
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 |
|
is_expired
is_expired() -> bool
Checks if the access token is expired.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether or not the token is expired.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If |
Example
token = WorldcatAccessToken(
key="my_WSKey_client_id",
secret="my_WSKey_secret",
scopes="WorldCatMetadataAPI",
agent="my_app/1.0.0")
print(token.is_expired())
#>False
Source code in bookops_worldcat\authorize.py
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 |
|