-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
45 changes: 45 additions & 0 deletions
45
compute_sdk/globus_compute_sdk/sdk/login_manager/authorizer_login_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |