From c7ef1a1c99d25dcd36f486b2df44e2b78da2e90e Mon Sep 17 00:00:00 2001 From: Lars Sorenson Date: Sat, 2 May 2015 15:25:54 -0400 Subject: [PATCH] Updated the create_oauth_token() function to include the ability to suppress printing the secrets and tokens, as well as returning the access tokens after the OAuth request. --- trello/util.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/trello/util.py b/trello/util.py index f3d926cf..0ce064a8 100755 --- a/trello/util.py +++ b/trello/util.py @@ -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. @@ -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 @@ -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()