Commit 172669ca authored by Gao, Shang's avatar Gao, Shang
Browse files

testing remote auth script

parent 5871f034
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ import json
import sys
import os
import time
import pickle

olcfatlas = 'ef1a9560-7ca1-11e5-992c-22000b96db58'

@@ -144,26 +143,18 @@ class crossbowGlobus(crossbowBase):
        """
        returns the authorization url for native app authentication
        """
        client = globus_sdk.NativeAppAuthClient(client_id=client_id)
        self.client = globus_sdk.NativeAppAuthClient(client_id=client_id)
        # pass refresh_tokens=True to request refresh tokens
        client.oauth2_start_flow(refresh_tokens=True)

        # pickle client for use in _dl_refresh_tokens
        authorize_url = client.oauth2_get_authorize_url()
        with open('globus_auth_client.pkl', 'wb') as f:
            pickle.dump(client, f, protocol=pickle.HIGHEST_PROTOCOL)
        self.client.oauth2_start_flow(refresh_tokens=True)

        authorize_url = self.client.oauth2_get_authorize_url()
        return authorize_url
        
    def _dl_refresh_tokens(self,auth_code):
        """
        manually saves refresh tokens to file
        """
        # load client from _get_authorize_url
        with open('globus_auth_client.pkl', 'rb') as f:
            client = pickle.load(f)
    
        token_response = client.oauth2_exchange_code_for_tokens(auth_code)
        token_response = self.client.oauth2_exchange_code_for_tokens(auth_code)
        tokens = token_response.by_resource_server
        self._save_tokens_to_file(token_file, tokens)
        
+6 −1
Original line number Diff line number Diff line
@@ -4,10 +4,15 @@ import sys
if len(sys.argv) > 1:
    url = sys.argv[1]
    
    cbow = crossbowGlobus(api_key="eaabd7d9-3cb4-4014-85fe-73736e658472",init=False)
    with open('globus_client.pkl', 'rb') as f:
        cbow = pickle.load(f)
    
    cbow._dl_refresh_tokens(url)

else:
    cbow = crossbowGlobus(api_key="eaabd7d9-3cb4-4014-85fe-73736e658472",init=False)
    url = cbow._get_authorize_url(cbow.client_id)
    sys.stdout.write(url)
    
    with open('globus_client.pkl', 'wb') as f:
        pickle.dump(cbow, f, protocol=pickle.HIGHEST_PROTOCOL)