Skip to content

Instantly share code, notes, and snippets.

@jjylik
Created February 11, 2024 15:04
Show Gist options
  • Save jjylik/fff2cfa966b8ee2f7e739a6b3d3d41ba to your computer and use it in GitHub Desktop.
Save jjylik/fff2cfa966b8ee2f7e739a6b3d3d41ba to your computer and use it in GitHub Desktop.
django-allauth SAML
class AcmeSocialAccountAdapter(DefaultSocialAccountAdapter):
# ...or save_user
def populate_user(self, request: Request, sociallogin: SocialLogin, data: dict) -> Any:
user = super().populate_user(request, sociallogin, data)
roles = sociallogin.account.extra_data.get("roles", [])
# Do something with extra attributes incoming from the SAML authentication response
user.roles = map_to_your_app_roles(roles)
return user
SOCIALACCOUNT_PROVIDERS = {
"saml": {
"APPS": [
# Apps can be configured in the DB or listed here
],
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment