Skip to content

Commit 73569a3

Browse files
committed
add patched-in local strategy for client credential access tokens
1 parent fb80f1d commit 73569a3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/posit/connect/external/databricks.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from ..oauth import Credentials
1313
from .external import is_local
1414

15+
import requests
16+
1517
POSIT_OAUTH_INTEGRATION_AUTH_TYPE = "posit-oauth-integration"
1618

1719
# The Databricks SDK CredentialsProvider == Databricks SQL HeaderFactory
@@ -78,6 +80,24 @@ def _get_auth_type(local_auth_type: str) -> str:
7880

7981
return POSIT_OAUTH_INTEGRATION_AUTH_TYPE
8082

83+
class PositLocalContentCredentialsProvider:
84+
85+
def __init__(self, token_endpoint_url: str, client_id: str, client_secret: str):
86+
self._token_endpoint_url = token_endpoint_url
87+
self._client_id = client_id
88+
self._client_secret = client_secret
89+
90+
def __call__(self) -> Dict[str, str]:
91+
response = requests.post(
92+
self._token_endpoint_url,
93+
auth=(self._client_id, self._client_secret),
94+
data={
95+
"grant_type": "client_credentials",
96+
"scope": "all-apis",
97+
},
98+
)
99+
credentials = Credentials(**response.json())
100+
return _new_bearer_authorization_header(credentials)
81101

82102
class PositContentCredentialsProvider:
83103
"""`CredentialsProvider` implementation which initiates a credential exchange using a content-session-token.

0 commit comments

Comments
 (0)