#NEWLINE# def create_oauth_token( expiration = None , scope = None , key = None , secret = None , name = None , output = True ) : #NEWLINE# #INDENT# "\n    Script to obtain an OAuth token from Trello.\n\n    Must have TRELLO_API_KEY and TRELLO_API_SECRET set in your environment\n    To set the token's expiration, set TRELLO_EXPIRATION as a string in your\n    environment settings (eg. 'never'), otherwise it will default to 30 days.\n\n    More info on token scope here:\n        https://trello.com/docs/gettingstarted/#getting-a-token-from-a-user\n    " #NEWLINE# request_token_url = 'https://trello.com/1/OAuthGetRequestToken' #NEWLINE# authorize_url = 'https://trello.com/1/OAuthAuthorizeToken' #NEWLINE# access_token_url = 'https://trello.com/1/OAuthGetAccessToken' #NEWLINE# expiration = ( expiration or os . environ . get ( 'TRELLO_EXPIRATION' , '30days' ) ) #NEWLINE# scope = ( scope or os . environ . get ( 'TRELLO_SCOPE' , 'read,write' ) ) #NEWLINE# trello_key = ( key or os . environ [ 'TRELLO_API_KEY' ] ) #NEWLINE# trello_secret = ( secret or os . environ [ 'TRELLO_API_SECRET' ] ) #NEWLINE# name = ( name or os . environ . get ( 'TRELLO_NAME' , 'py-trello' ) ) #NEWLINE# session = OAuth1Session ( client_key = trello_key , client_secret = trello_secret ) #NEWLINE# response = session . fetch_request_token ( request_token_url ) #NEWLINE# ( resource_owner_key , resource_owner_secret ) = ( response . get ( 'oauth_token' ) , response . get ( 'oauth_token_secret' ) ) #NEWLINE# if output : #NEWLINE# #INDENT# print ( 'Request Token:' ) #NEWLINE# print ( ( '    - oauth_token        = %s' % resource_owner_key ) ) #NEWLINE# print ( ( '    - oauth_token_secret = %s' % resource_owner_secret ) ) #NEWLINE# print ( '' ) #NEWLINE# #UNINDENT# print ( 'Go to the following link in your browser:' ) #NEWLINE# print ( '{authorize_url}?oauth_token={oauth_token}&scope={scope}&expiration={expiration}&name={name}' . format ( authorize_url = authorize_url , oauth_token = resource_owner_key , expiration = expiration , scope = scope , name = name ) ) #NEWLINE# try : #NEWLINE# #INDENT# inputFunc = raw_input #NEWLINE# #UNINDENT# except NameError : #NEWLINE# #INDENT# inputFunc = input #NEWLINE# #UNINDENT# accepted = 'n' #NEWLINE# while ( accepted . lower ( ) == 'n' ) : #NEWLINE# #INDENT# accepted = inputFunc ( 'Have you authorized me? (y/n) ' ) #NEWLINE# #UNINDENT# oauth_verifier = inputFunc ( 'What is the PIN? ' ) #NEWLINE# session = OAuth1Session ( client_key = trello_key , client_secret = trello_secret , resource_owner_key = resource_owner_key , resource_owner_secret = resource_owner_secret , verifier = oauth_verifier ) #NEWLINE# access_token = session . fetch_access_token ( access_token_url ) #NEWLINE# if output : #NEWLINE# #INDENT# print ( 'Access Token:' ) #NEWLINE# print ( ( '    - oauth_token        = %s' % access_token [ 'oauth_token' ] ) ) #NEWLINE# print ( ( '    - oauth_token_secret = %s' % access_token [ 'oauth_token_secret' ] ) ) #NEWLINE# print ( '' ) #NEWLINE# print ( 'You may now access protected resources using the access tokens above.' ) #NEWLINE# print ( '' ) #NEWLINE# #UNINDENT# return access_token