|
8 | 8 | import sys |
9 | 9 |
|
10 | 10 | from fair_research_login.client import NativeClient |
11 | | -from globus_sdk import TransferAPIError, TransferClient, TransferData |
| 11 | +from globus_sdk import ( |
| 12 | + AccessTokenAuthorizer, |
| 13 | + NativeAppAuthClient, |
| 14 | + TransferAPIError, |
| 15 | + TransferClient, |
| 16 | + TransferData, |
| 17 | +) |
12 | 18 | from globus_sdk.services.transfer.response.iterable import IterableTransferResponse |
13 | 19 | from six.moves.urllib.parse import urlparse |
14 | 20 |
|
@@ -128,13 +134,24 @@ def globus_activate(hpss: str): |
128 | 134 | if remote_endpoint.upper() in hpss_endpoint_map.keys(): |
129 | 135 | remote_endpoint = hpss_endpoint_map.get(remote_endpoint.upper()) |
130 | 136 |
|
131 | | - native_client = NativeClient( |
132 | | - client_id="6c1629cf-446c-49e7-af95-323c6412397f", |
133 | | - app_name="Zstash", |
134 | | - default_scopes="openid urn:globus:auth:scope:transfer.api.globus.org:all", |
135 | | - ) |
136 | | - native_client.login(no_local_server=True, refresh_tokens=True) |
137 | | - transfer_authorizer = native_client.get_authorizers().get("transfer.api.globus.org") |
| 137 | + # Authentication -- Globus Consents |
| 138 | + # Initialize the NativeAppAuthClient with the client ID |
| 139 | + CLIENT_ID = "6c1629cf-446c-49e7-af95-323c6412397f" |
| 140 | + client = NativeAppAuthClient(CLIENT_ID, app_name="Zstash") |
| 141 | + # Start the OAuth2 flow |
| 142 | + client.oauth2_start_flow(refresh_tokens=True) |
| 143 | + # Get the authorization URL and prompt the user to visit it |
| 144 | + authorize_url = client.oauth2_get_authorize_url() |
| 145 | + print(f"Please go to this URL and login: {authorize_url}") |
| 146 | + # Get the authorization code from the user |
| 147 | + auth_code = input("Please enter the code you get after login here: ").strip() |
| 148 | + # Exchange the authorization code for tokens |
| 149 | + token_response = client.oauth2_exchange_code_for_tokens(auth_code) |
| 150 | + # Extract the access token for the Globus Transfer service |
| 151 | + globus_transfer_data = token_response.by_resource_server["transfer.api.globus.org"] |
| 152 | + globus_transfer_token = globus_transfer_data["access_token"] |
| 153 | + # Initialize the TransferClient with the obtained access token |
| 154 | + transfer_authorizer = AccessTokenAuthorizer(globus_transfer_token) |
138 | 155 | transfer_client = TransferClient(authorizer=transfer_authorizer) |
139 | 156 |
|
140 | 157 | for ep_id in [local_endpoint, remote_endpoint]: |
|
0 commit comments