Before you can use SdkClient, you must follow the OAuth 2.0 authorization code flow to gain access to the content stored in a user’s Verizon Personal Cloud Storage account. This is a two-step process: you must first obtain an authorization code, then exchange the authorization code for an access token and a refresh token.
NOTE: The Callback URL is case sensitive.
Authentication and Authorization methods are included in the Cloud
class which is the gateway to access Personal Cloud Storage APIs.
authorize_url
refresh
token
To authenticate the SDK, pass the client key, secret, and callback URL to the SDK. You must use the values that you have obtained from Key Management when you registered your app.
NOTE: Refer to Getting Credentials to Use the Personal Cloud Storage APIs page in the API Developer Guide for information on how to register our app.
Code Sample
from thingspace.cloud import Cloud
cloud = Cloud(
client_key='your client key',
client_secret='your client secret',
callback_url='your callback url',
)
To retrieve the authorization URL, call the authorize
method without specifying any parameters.
Code Sample
auth_url = cloud.authorize_url()
When an API call results in a 401 response, the SDK automatically refreshes the access token. The python SDK accepts a callback function that is executed immediately after the access token has been refreshed.
Code Sample
def refresh_callback(tokens):
print('newly refreshed tokens' + str(tokens))
# you may also pass 'on_refreshed' in the Cloud's Constructor
cloud.on_refreshed = refresh_callback
To refresh an access token manually, call the refresh
method as in the following example:
Code Sample
refreshed_tokens = cloud.refresh()
Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.