Skip to content

Commit 4b247bd

Browse files
authored
Merge pull request #227 from hydroserver2/238-workspaces
238 workspaces
2 parents b9a1848 + 05b9658 commit 4b247bd

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

hydroserver/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"allauth.socialaccount.providers.orcid",
6464
"iam.auth.providers.hydroshare",
6565
"iam.auth.providers.orcidsandbox",
66+
"iam.auth.providers.utahid",
6667
"corsheaders",
6768
"easyaudit",
6869
"sensorthings",
@@ -254,7 +255,7 @@
254255
"OPTIONS": {
255256
"bucket_name": config("MEDIA_BUCKET_NAME", default=None),
256257
"location": "media",
257-
"default_acl": "authenticatedRead"
258+
"default_acl": "publicRead"
258259
},
259260
},
260261
"staticfiles": {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from allauth.socialaccount.providers.base import ProviderAccount
2+
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
3+
from iam.auth.providers.utahid.views import UtahIdOAuth2Adapter
4+
5+
6+
class UtahIdAccount(ProviderAccount):
7+
def to_str(self):
8+
return self.account.extra_data.get("name", super().to_str())
9+
10+
11+
class UtahIdProvider(OAuth2Provider):
12+
id = "utahid"
13+
name = "UtahID"
14+
account_class = UtahIdAccount
15+
oauth2_adapter_class = UtahIdOAuth2Adapter
16+
17+
def get_default_scope(self):
18+
return ["openid", "email", "profile"]
19+
20+
def extract_uid(self, data):
21+
return str(data["sub"])
22+
23+
def extract_common_fields(self, data):
24+
return dict(
25+
email=data.get("email"),
26+
last_name=data.get("family_name"),
27+
first_name=data.get("given_name"),
28+
)
29+
30+
31+
provider_classes = [UtahIdProvider]

iam/auth/providers/utahid/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
2+
from .provider import UtahIdProvider
3+
4+
5+
urlpatterns = default_urlpatterns(UtahIdProvider)

iam/auth/providers/utahid/views.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import requests
2+
from allauth.socialaccount.providers.oauth2.views import OAuth2Adapter, OAuth2LoginView, OAuth2CallbackView
3+
4+
5+
class UtahIdOAuth2Adapter(OAuth2Adapter):
6+
provider_id = "utahid"
7+
8+
access_token_url = "https://login.dts.utah.gov:443/sso/oauth2/access_token"
9+
authorize_url = "https://login.dts.utah.gov:443/sso/oauth2/authorize"
10+
profile_url = "https://login.dts.utah.gov:443/sso/oauth2/userinfo"
11+
12+
def complete_login(self, request, app, token, **kwargs):
13+
headers = {"Authorization": f"Bearer {token.token}"}
14+
response = requests.get(self.profile_url, headers=headers)
15+
response.raise_for_status()
16+
extra_data = response.json()
17+
18+
return self.get_provider().sociallogin_from_response(request, extra_data)
19+
20+
21+
oauth2_login = OAuth2LoginView.adapter_view(UtahIdOAuth2Adapter)
22+
oauth2_callback = OAuth2CallbackView.adapter_view(UtahIdOAuth2Adapter)

iam/static/providers/utahid.png

16.3 KB
Loading

0 commit comments

Comments
 (0)