You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I registered a custom OAuth app integration, to use Databricks as OAuth provider for my Dash application. I used the SDK to create the app integration:
Then, I am using the databricks.sdk.oauth classess following example here: https://github.com/databricks/databricks-sdk-py/blob/main/examples/flask_app_with_oauth.py to incorporate the 3-legged OAuth flow to my Dash app. The flow works fine. I am loading credentials from the flask session using a decorator, and I decorate my Dash callback functions with it, to pass connection object to the callback:
defauthorize_databricks(func):
defwrapper(*args, **kwargs):
if'databricks_creds'insession:
credentials_provider=SessionCredentials.from_dict(oauth_client, session["databricks_creds"])
connection=ConnectionBuilder(credentials_provider, db_config)
ifconnection:
returnfunc(*args, connection=connection, **kwargs) # Pass the 'token' variable to the functionelse:
returndcc.Location(pathname=f'/{APP_ABBREVIATION}/databrickslogin', id='redirection')
returnwrapper
Problem is that I do not obtain refresh_token from Databricks OAuth server. So when the token is expired, the SessionCredentials class is trying to refresh it, using the refresh method:
classSessionCredentials(Refreshable):
def__init__(self, client: 'OAuthClient', token: Token):
self._client=clientsuper().__init__(token)
defas_dict(self) ->dict:
return {'token': self._token.as_dict()}
@staticmethoddeffrom_dict(client: 'OAuthClient', raw: dict) ->'SessionCredentials':
returnSessionCredentials(client=client, token=Token.from_dict(raw['token']))
defauth_type(self):
"""Implementing CredentialsProvider protocol"""# TODO: distinguish between Databricks IDP and Azure ADreturn'oauth'def__call__(self, *args, **kwargs):
"""Implementing CredentialsProvider protocol"""definner() ->Dict[str, str]:
return {'Authorization': f"Bearer {self.token().access_token}"}
returninnerdefrefresh(self) ->Token:
refresh_token=self._token.refresh_tokenifnotrefresh_token:
raiseValueError('oauth2: token expired and refresh token is not set')
params= {'grant_type': 'refresh_token', 'refresh_token': refresh_token}
headers= {}
if'microsoft'inself._client.token_url:
# Tokens issued for the 'Single-Page Application' client-type may# only be redeemed via cross-origin requestsheaders= {'Origin': self._client.redirect_url}
returnretrieve_token(client_id=self._client.client_id,
client_secret=self._client.client_secret,
token_url=self._client.token_url,
params=params,
use_params=True,
headers=headers)
This leads to raising the ValueError 'oauth2: token expired and refresh token is not set'.
How to make the OAuth server send refresh token? Do I need some special configuration? I haven't seen any fitting options in the API spec here: https://docs.databricks.com/api/account/customappintegration/create , tried setting the app to both confidential=True and confidential=False, but no change. the response from consent.exchange_callback_parameters(request.args).as_dict():
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I registered a custom OAuth app integration, to use Databricks as OAuth provider for my Dash application. I used the SDK to create the app integration:
Then, I am using the databricks.sdk.oauth classess following example here: https://github.com/databricks/databricks-sdk-py/blob/main/examples/flask_app_with_oauth.py to incorporate the 3-legged OAuth flow to my Dash app. The flow works fine. I am loading credentials from the flask session using a decorator, and I decorate my Dash callback functions with it, to pass connection object to the callback:
Problem is that I do not obtain refresh_token from Databricks OAuth server. So when the token is expired, the SessionCredentials class is trying to refresh it, using the refresh method:
This leads to raising the ValueError 'oauth2: token expired and refresh token is not set'.
How to make the OAuth server send refresh token? Do I need some special configuration? I haven't seen any fitting options in the API spec here: https://docs.databricks.com/api/account/customappintegration/create , tried setting the app to both confidential=True and confidential=False, but no change. the response from
consent.exchange_callback_parameters(request.args).as_dict()
:always lacks refresh_token, the dict only has access_token, and expiry.
Thanks for any tips to unblock this.
Beta Was this translation helpful? Give feedback.
All reactions