Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass locally defined scopes to RemoteClientConfigStore #1553

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions flytekit/clients/auth/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ def __init__(
client_id: str,
client_secret: str,
cfg_store: ClientConfigStore,
header_key: str = None,
header_key: typing.Optional[str] = None,
scopes: typing.Optional[typing.List[str]] = None,
):
if not client_id or not client_secret:
raise ValueError("Client ID and Client SECRET both are required.")
cfg = cfg_store.get_client_config()
self._token_endpoint = cfg.token_endpoint
self._scopes = cfg.scopes
# Use scopes from `flytekit.configuration.PlatformConfig` if passed
self._scopes = scopes or cfg.scopes
self._client_id = client_id
self._client_secret = client_secret
super().__init__(endpoint, cfg.header_key or header_key)
Expand Down
1 change: 1 addition & 0 deletions flytekit/clients/auth_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def get_authenticator(cfg: PlatformConfig, cfg_store: ClientConfigStore) -> Auth
client_id=cfg.client_id,
client_secret=cfg.client_credentials_secret,
cfg_store=cfg_store,
scopes=cfg.scopes,
)
elif cfg_auth == AuthType.EXTERNAL_PROCESS or cfg_auth == AuthType.EXTERNALCOMMAND:
client_cfg = None
Expand Down
25 changes: 24 additions & 1 deletion tests/flytekit/unit/clients/auth/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_get_token(mock_requests):


@patch("flytekit.clients.auth.authenticator.requests")
def test_client_creds_authenticator(mock_requests):
def test_client_creds_authenticator_without_custom_scopes(mock_requests):
authn = ClientCredentialsAuthenticator(
ENDPOINT, client_id="client", client_secret="secret", cfg_store=static_cfg_store
)
Expand All @@ -92,4 +92,27 @@ def test_client_creds_authenticator(mock_requests):
response.json.return_value = json.loads("""{"access_token": "abc", "expires_in": 60}""")
mock_requests.post.return_value = response
authn.refresh_credentials()
expected_scopes = static_cfg_store.get_client_config().scopes

assert authn._creds
assert authn._scopes == expected_scopes


@patch("flytekit.clients.auth.authenticator.requests")
def test_client_creds_authenticator_with_custom_scopes(mock_requests):
expected_scopes = ["foo", "baz"]
authn = ClientCredentialsAuthenticator(
ENDPOINT,
client_id="client",
client_secret="secret",
cfg_store=static_cfg_store,
scopes=expected_scopes,
)
response = MagicMock()
response.status_code = 200
response.json.return_value = json.loads("""{"access_token": "abc", "expires_in": 60}""")
mock_requests.post.return_value = response
authn.refresh_credentials()

assert authn._creds
assert authn._scopes == expected_scopes