Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unified Custom Validators (hooks) for Grant and Server #613

@JonathanHuot

Description

@JonathanHuot

Describe the feature

Adding Custom Validators to Grants is doable by using the GrantType interface (see https://github.com/oauthlib/oauthlib/blob/v2.1.0/oauthlib/oauth2/rfc6749/grant_types/base.py#L49-L56). However, we provide pre_configured classes which does not expose "easily" these grant types. Also, we have multiple different kind of "hooks", for Server.__init__() we have token_generator=hook, token_expires_in=hook, refresh_token_generator=hook. Then for GrantTypeBase have custom_validators (dict) (pre_auth/post_auth/pre_token/post_token), register_code_modifier(hook) and register_token_modifier(hook).

It is complicated for OAuth2 provider implementation but become worst when using the OpenID Connect openid.pre_configured which has 8 GrantTypeBase and 3 Dispatchers, where each Dispatcher has two Grant with different names (e.g. default_auth_grant or default_implicit_grant).

E.g. Current OAuth2 Provider example:

oauthlib_server = oauth2.Server(..)
oauthlib_server._response_types["token"].custom_validators.pre_auth.append(myhook)
oauthlib_server._response_types["code"].custom_validators.pre_auth.append(myhook)
oauthlib_server._response_types["code"].register_code_modifier(mymodifier)

Same hooks with OpenID Provider is just impossible, or will span to more than 20 lines of code.

I open this issue to raise the problem and see what's the solutions we could imagine to progress toward a better place.

Additional context

It applies to OAuth2 Provider and OpenID Connect Provider server code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions