Skip to content

Commit

Permalink
Updated the create_oauth_token() function to include the ability to s…
Browse files Browse the repository at this point in the history
…uppress printing the secrets and tokens, as well as returning the access tokens after the OAuth request.
  • Loading branch information
larssorenson committed May 2, 2015
1 parent 3dfaa8c commit c7ef1a1
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions trello/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from requests_oauthlib import OAuth1Session

def create_oauth_token(expiration=None, scope=None, key=None, secret=None, name=None):
def create_oauth_token(expiration=None, scope=None, key=None, secret=None, name=None, output=True):
"""
Script to obtain an OAuth token from Trello.
Expand Down Expand Up @@ -33,10 +33,11 @@ def create_oauth_token(expiration=None, scope=None, key=None, secret=None, name=
response = session.fetch_request_token(request_token_url)
resource_owner_key, resource_owner_secret = response.get('oauth_token'), response.get('oauth_token_secret')

print("Request Token:")
print(" - oauth_token = %s" % resource_owner_key)
print(" - oauth_token_secret = %s" % resource_owner_secret)
print("")
if output:
print("Request Token:")
print(" - oauth_token = %s" % resource_owner_key)
print(" - oauth_token_secret = %s" % resource_owner_secret)
print("")

# Step 2: Redirect to the provider. Since this is a CLI script we do not
# redirect. In a web application you would redirect the user to the URL
Expand Down Expand Up @@ -76,12 +77,15 @@ def create_oauth_token(expiration=None, scope=None, key=None, secret=None, name=
verifier=oauth_verifier)
access_token = session.fetch_access_token(access_token_url)

print("Access Token:")
print(" - oauth_token = %s" % access_token['oauth_token'])
print(" - oauth_token_secret = %s" % access_token['oauth_token_secret'])
print("")
print("You may now access protected resources using the access tokens above.")
print("")
if output:
print("Access Token:")
print(" - oauth_token = %s" % access_token['oauth_token'])
print(" - oauth_token_secret = %s" % access_token['oauth_token_secret'])
print("")
print("You may now access protected resources using the access tokens above.")
print("")

return access_token

if __name__ == '__main__':
create_oauth_token()
Expand Down

0 comments on commit c7ef1a1

Please sign in to comment.