Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
django_openidconnect/provider.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (51 sloc)
1.95 KB
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
from allauth.socialaccount import providers | |
from allauth.socialaccount.providers.base import ProviderAccount | |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider | |
from django.utils.http import urlencode | |
from django.dispatch import receiver | |
from allauth.socialaccount.signals import social_account_added | |
from django.contrib.auth.models import Group | |
@receiver(social_account_added) | |
def addUserToGroup(request,sociallogin,**kwargs): | |
print("socialaccountadded") | |
user = sociallogin.account.user | |
user.is_active=True | |
try: | |
user.groups.append(Group.objects.get(name="mpiwg")) | |
except: | |
pass | |
user.save() | |
class OpenIdConnectAccount(ProviderAccount): | |
def get_profile_url(self): | |
# profile_url = "u/3195025850" | |
return 'https://id.mpiwg-berlin.mpg.de/openid' | |
def get_avatar_url(self): | |
return "" | |
return self.account.extra_data.get('figureurl_OpenIdConnect_1') | |
def to_str(self): | |
dflt = super(OpenIdConnectAccount, self).to_str() | |
return self.account.extra_data.get('name', dflt) | |
class OpenIdConnectProvider(OAuth2Provider): | |
#id = 'openidconnect' | |
id = "OpenIdConnect" | |
name = 'MPIWG' | |
package = 'allauth.socialaccount.providers.OpenIdConnect' | |
OPENIDBASE_URL="https://id.mpiwg-berlin.mpg.de/openid" | |
access_token_url = OPENIDBASE_URL+'/token' | |
authorize_url = OPENIDBASE_URL+'/authorize' | |
account_class = OpenIdConnectAccount | |
###client_id | |
#26990fe0-5190-42d9-91ac-720e03bb333e | |
#redirect_uri | |
#http://datastore-dev.mpiwg-berlin.mpg.de:8080/giles/signin/mitreidconnect | |
#response_type | |
#code | |
#state | |
#e68cb07a-835a-49a0-b68a-c1c5cb18e8b0 | |
def extract_uid(self, data): | |
return data["email"] | |
#return data['idstr'] | |
def extract_common_fields(self, data): | |
return dict(username=data.get('sub'), | |
name=data.get('name')) | |
providers.registry.register(OpenIdConnectProvider) |