Skip to content

Conversation

@huntabyte
Copy link
Contributor

@huntabyte huntabyte commented Jun 24, 2022

Fixes: #8854

Added a custom pipeline handler function per python-social-auth docs

This pipeline handler assigns the default group(s) to remote auth users. Successfully tested with Microsoft Azure AD, however, there is nothing particular related to Azure AD in this configuration.

@jeremystretch
Copy link
Member

Awesome work, thanks for tackling this!

@jeremystretch jeremystretch merged commit 221ddc6 into netbox-community:develop Jun 28, 2022
@HolySephi
Copy link

HolySephi commented Jul 13, 2022

This change removes the possibility to define my own SOCIAL_AUTH_PIPELINE in configuration.py and thus removes the function to assign roles from auth claims as groups via custom_pipeline. Removing thhis static SOCIAL_AUTH_PIPELINE from settings.py allows my own pipeline to run again.
Bug: SOCIAL_AUTH_PIPELINE from configuration.py does not overwrite this SOCIAL_AUTH_PIPELINE from settings.py

if you are interested - this is the custom_pipeline to set auth claim roles to groups (tested and used with AzureAD):

from django.contrib.auth.models import Group

class AuthFailed(Exception):
    pass`

def set_role(response, user, backend, *args, **kwargs):
    try:
        role = response['roles'][0]
    except KeyError:
        raise AuthFailed("No role assigned")

    try:
        group = Group.objects.get(name="{}".format(role))
    except Group.DoesNotExist:
        raise AuthFailed("Unknown role")

and adding 'netbox.custom_pipeline.set_role' to my own SOCIAL_AUTH_PIPELINE

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REMOTE_AUTH_DEFAULT_GROUPS not adding new users to group

3 participants