Skip to content

Commit

Permalink
Add an authorizer login manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchard committed Sep 1, 2023
1 parent 7b366c6 commit 0d074b1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compute_sdk/globus_compute_sdk/sdk/login_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from .decorators import requires_login
from .manager import ComputeScopes, LoginManager
from .authorizer_login_manager import AuthorizerLoginManager
from .protocol import LoginManagerProtocol

__all__ = (
"LoginManager",
"ComputeScopes",
"LoginManagerProtocol",
"requires_login",
"AuthorizerLoginManager",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

import logging

import globus_sdk
from globus_sdk.scopes import AuthScopes

from globus_compute_sdk.sdk.login_manager.protocol import LoginManagerProtocol
from globus_compute_sdk.sdk.web_client import WebClient

from .manager import ComputeScopeBuilder

log = logging.getLogger(__name__)

ComputeScopes = ComputeScopeBuilder()


class AuthorizerLoginManager(LoginManagerProtocol):
"""
Implements a LoginManager that can be instantiated with authorizers.
This manager can be used to create an Executor with authorizers created
from previously acquired tokens, rather than requiring a Native App login
flow or Client credentials.
"""

def __init__(self, authorizers: dict[str, globus_sdk.RefreshTokenAuthorizer]):
self.authorizers = authorizers

def get_auth_client(self) -> globus_sdk.AuthClient:
return globus_sdk.AuthClient(authorizer=self.authorizers[AuthScopes.openid])

def get_web_client(
self, *, base_url: str | None = None, app_name: str | None = None
) -> WebClient:
return WebClient(
base_url=base_url,
app_name=app_name,
authorizer=self.authorizers[ComputeScopes.resource_server],
)

def ensure_logged_in(self):
return True

def logout(self):
log.warning("Logout cannot be invoked from a TokenLoginManager.")

0 comments on commit 0d074b1

Please sign in to comment.