-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds code to refresh DDS token using OAuth token. Upgrades DukeDSClient requirement for Duke-GCB/DukeDSClient#314 changes.
- Loading branch information
1 parent
0d60102
commit 8e835d5
Showing
3 changed files
with
68 additions
and
15 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
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,16 +1,41 @@ | ||
from ddsc.sdk.client import Client | ||
from ddsc.core.ddsapi import OAuthDataServiceAuth | ||
from ddsc.config import Config | ||
from gcb_web_auth.models import DDSUserCredential | ||
from gcb_web_auth.utils import get_dds_config_for_credentials, get_dds_token, make_auth_config | ||
from gcb_web_auth.utils import get_dds_config_for_credentials, get_oauth_token, get_default_dds_endpoint | ||
|
||
|
||
def make_client(user): | ||
try: | ||
dds_credential = DDSUserCredential.objects.get(user=user) | ||
config = get_dds_config_for_credentials(dds_credential) | ||
return Client(config=config) | ||
except DDSUserCredential.DoesNotExist: | ||
# No DDSUserCredential configured for this user, fall back to OAuth | ||
# May raise an OAuthConfigurationException | ||
dds_token = get_dds_token(user) | ||
config = make_auth_config(dds_token.key) | ||
client = Client(config=config) | ||
return client | ||
endpoint = get_default_dds_endpoint() | ||
config = Config() | ||
config.update_properties({ | ||
Config.URL: endpoint.api_root, | ||
}) | ||
authentication_service_id = endpoint.openid_provider_service_id | ||
|
||
def create_data_service_auth(config, set_status_msg=print): | ||
return CustomOAuthDataServiceAuth(user, authentication_service_id, config, set_status_msg=set_status_msg) | ||
|
||
return Client(config=config, create_data_service_auth=create_data_service_auth) | ||
|
||
|
||
class CustomOAuthDataServiceAuth(OAuthDataServiceAuth): | ||
def __init__(self, user, authentication_service_id, config, set_status_msg=print): | ||
super().__init__(config, set_status_msg) | ||
self._auth = None | ||
self.user = user | ||
self.authentication_service_id = authentication_service_id | ||
|
||
def create_oauth_access_token(self): | ||
oauth_token = get_oauth_token(self.user) | ||
return oauth_token.token_dict.get('access_token') | ||
|
||
def get_authentication_service_id(self): | ||
return self.authentication_service_id |
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