Skip to content

Limit Clients to a subset of Users #442

Answered by jaap3
jaap3 asked this question in Q&A
Mar 22, 2022 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

I ended up implementing this myself in the authorize view:

psuedo code:

class BaseClient(ClientMixin):
    def is_enabled_for_user(self, user):
        # Override this is clients with special access rules
        return not user.is_anonymous
    

def authorize(request):
    try:
        grant = oauth2_server.get_consent_grant(request, end_user=request.user)
    except OAuth2Error as error:
        return oauth2_server.handle_error_response(request, error)
        
    user = request.user if grant.client.is_enabled_for_user(request.user) else None
    return oauth2_server.create_authorization_response(request, grant_user=user)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jaap3
Comment options

@lepture
Comment options

Answer selected by lepture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants