Skip to content

Commit

Permalink
Add methods to return OAuth tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
kwilcox committed Mar 14, 2016
1 parent 673fa8c commit d5f6add
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pypodio2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,31 @@ def OAuthClient(api_key, api_secret, login, password, user_agent=None,
return AuthorizingClient(domain, auth, user_agent=user_agent)


def OAuthClientReturningToken(api_key, api_secret, login, password, user_agent=None,
domain="https://api.podio.com"):
auth = transport.OAuthAuthorization(login, password,
api_key, api_secret, domain)
return auth.token, AuthorizingClient(domain, auth, user_agent=user_agent)


def OAuthClientUsingToken(token, user_agent=None,
domain="https://api.podio.com"):
auth = transport.OAuthTokenAuthorization(token)
return AuthorizingClient(domain, auth, user_agent=user_agent)


def OAuthClientRefresh(api_key, api_secret, refresh_token, user_agent=None,
domain="https://api.podio.com"):
auth = transport.OAuthRefreshAuthorization(api_key, api_secret,
refresh_token, domain)
return auth.token, AuthorizingClient(domain, auth, user_agent=user_agent)


def OAuthAppClient(client_id, client_secret, app_id, app_token, user_agent=None,
domain="https://api.podio.com"):

auth = transport.OAuthAppAuthorization(app_id, app_token,
client_id, client_secret, domain)

return AuthorizingClient(domain, auth, user_agent=user_agent)


Expand Down
28 changes: 28 additions & 0 deletions pypodio2/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ def to_headers(self):
return {'authorization': "OAuth2 %s" % self.access_token}


class OAuthRefreshAuthorization(object):
"""Regenerates headers for Podio OAuth2 Authorization"""

def __init__(self, key, secret, refresh_token, domain):
body = {'grant_type': 'refresh_token',
'client_id': key,
'client_secret': secret,
'refresh_token': refresh_token}
h = Http(disable_ssl_certificate_validation=True)
headers = {'content-type': 'application/x-www-form-urlencoded'}
response, data = h.request(domain + "/oauth/token", "POST",
urlencode(body), headers=headers)
self.token = OAuthToken(_handle_response(response, data))

def __call__(self):
return self.token.to_headers()


class OAuthTokenAuthorization(object):
"""Generates headers for Podio OAuth2 Authorization"""

def __init__(self, token):
self.token = token

def __call__(self):
return self.token.to_headers()


class OAuthAuthorization(object):
"""Generates headers for Podio OAuth2 Authorization"""

Expand Down

0 comments on commit d5f6add

Please sign in to comment.