Skip to content

Commit 7dee280

Browse files
committed
add from_host
1 parent c8d63e1 commit 7dee280

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

databricks/sdk/oauth.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,29 @@ def __init__(self,
472472
self._oidc_endpoints = oidc_endpoints
473473
self._scopes = scopes
474474

475+
@staticmethod
476+
def from_host(self,
477+
host: str,
478+
client_id: str,
479+
redirect_url: str,
480+
*,
481+
scopes: List[str] = None,
482+
client_secret: str = None) -> 'OAuthClient':
483+
from .core import Config
484+
from .credentials_provider import credentials_strategy
485+
486+
@credentials_strategy('noop', [])
487+
def noop_credentials(_: any):
488+
return lambda: {}
489+
490+
config = Config(host=host, credentials_strategy=noop_credentials)
491+
if not scopes:
492+
scopes = ['all-apis']
493+
oidc = config.oidc_endpoints
494+
if not oidc:
495+
raise ValueError(f'{host} does not support OAuth')
496+
return OAuthClient(oidc, redirect_url, client_id, scopes, client_secret)
497+
475498
def initiate_consent(self) -> Consent:
476499
state = secrets.token_urlsafe(16)
477500

0 commit comments

Comments
 (0)