Skip to content

Commit

Permalink
Allow the use of different Native App Client IDs with globus_auth_uti…
Browse files Browse the repository at this point in the history
…ls.py. Some misc formatting cleanup in same.
  • Loading branch information
mikedarcy committed Jan 8, 2021
1 parent c444ac4 commit 439ca77
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions deriva/core/utils/globus_auth_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def update_scope(self, scope_id, scope):
if not (scope_id and scope):
raise UsageException("The scope_id and scope arguments are required.")

r = self.client.put("/v2/api/scopes/{scope_id}".format(scope_id=scope_id),
json_body=self.from_json(scope))
r = self.client.put("/v2/api/scopes/{scope_id}".format(scope_id=scope_id), json_body=self.from_json(scope))
return r.data

def add_fqdn_to_client(self, fqdn):
Expand Down Expand Up @@ -338,8 +337,7 @@ def create_scope_with_deps(self, name, description, suffix, dependent_scopes=[],
}
}

r = self.client.post("/v2/api/clients/{client_id}/scopes".format(client_id=self.client_id),
json_body=scope)
r = self.client.post("/v2/api/clients/{client_id}/scopes".format(client_id=self.client_id), json_body=scope)
return r.data

def delete_scope(self, scope_name):
Expand Down Expand Up @@ -471,17 +469,18 @@ def clear_tokens(self, requested_scopes=()):
class GlobusNativeLogin:
def __init__(self, **kwargs):
self.client = None
self.client_id = kwargs.get("client_id") or NATIVE_APP_CLIENT_ID
self.native_app_client_id = kwargs.get("native_app_client_id") or NATIVE_APP_CLIENT_ID
self.hosts = kwargs.get("hosts")
self.config_file = kwargs.get("config_file")
self.exclude_defaults = kwargs.get("exclude_defaults")
self.default_scopes = DEFAULT_SCOPES.copy()

try:
storage_file = 'globus-credential.json'
storage_file = 'globus-credential%s.json' % (("-" + self.native_app_client_id)
if self.native_app_client_id != NATIVE_APP_CLIENT_ID else "")
storage = DerivaJSONTokenStorage(filename=os.path.join(DEFAULT_CONFIG_PATH, storage_file))
self.client = NativeClient(
client_id=self.client_id,
client_id=self.native_app_client_id,
token_storage=storage,
app_name="Login from deriva-client on %s [%s]%s" %
(platform.uname()[1],
Expand Down Expand Up @@ -696,6 +695,8 @@ def __init__(self, *args, **kwargs):
help="Globus Auth Client ID")
self.parser.add_argument('--client-secret', '-k', metavar='<client secret key>',
help="Globus Auth Client Secret")
self.parser.add_argument('--native-app-client-id', '-n', metavar='<native app client id>',
help="Globus Native App Client ID")

self.subparsers = self.parser.add_subparsers(title='sub-commands', dest='subcmd')

Expand Down

0 comments on commit 439ca77

Please sign in to comment.