bookops_worldcat.authorize
This module provides means to authenticate and obtain a WorldCat access token.
WorldcatAccessToken
WorldcatAccessToken(
key: str,
secret: str,
scopes: Union[str, List],
principal_id: str,
principal_idns: str,
agent: str = None,
timeout: Union[float, Tuple] = None,
)
Requests Worldcat access token. Authenticates and authorizes using Client Credentials Grant. Does not support Explicit Authorization Code and Refresh Token flows. Token with correctly bonded scopes can then be passed into a session of particular web service to authorize requests for resources. More on OCLC's web services authorization: https://www.oclc.org/developer/develop/authentication/oauth/client-credentials-grant.en.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
your WSKey public client_id |
required |
secret |
str
|
your WSKey secret |
required |
scopes |
Union[str, List]
|
request scopes for the access token |
required |
principal_id |
str
|
principalID (required for read/write endpoints) |
required |
principal_idns |
str
|
principalIDNS (required for read/write endpoints) |
required |
agent |
str
|
"User-agent" parameter to be passed in the request header; usage strongly encouraged |
None
|
timeout |
Union[float, Tuple]
|
how long to wait for server to send data before giving up; default value is 3 seconds |
None
|
Examples:
>>> from bookops_worldcat import WorldcatAccessToken
>>> token = WorldcatAccessToken(
key="my_WSKey_client_id",
secret="my_WSKey_secret",
scope="WorldCatMetadataAPI",
principal_id="your principalID here",
principal_idns="your principalIDNS here",
agent="my_app/1.0.0")
>>> token.token_str
"tk_Yebz4BpEp9dAsghA7KpWx6dYD1OZKWBlHjqW"
>>> token.is_expired()
False
>>> 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"}
>>> 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="}
Source code in bookops_worldcat\authorize.py
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 |
|
is_expired
is_expired()
Checks if the access token is expired.
Returns:
Type | Description |
---|---|
bool |
Example:
token.is_expired() False
Source code in bookops_worldcat\authorize.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|