Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing custom token generator #732

Open
KhashayarMirMS opened this issue Aug 17, 2019 · 3 comments
Open

Implementing custom token generator #732

KhashayarMirMS opened this issue Aug 17, 2019 · 3 comments

Comments

@KhashayarMirMS
Copy link

Hi,
I want to implement a custom token generator to use JWT in DOT.
There are several issues related to this problem which lead to this pull request: #467. But the pull request is about writing custom models for tokens which doesn't handle token generation.

The solution that I've currently found is to write a custom Server Class to pass a custom generator function to BearerToken. But I've seen that Server Class instances are initialized with a token_generator function passed to them, but I can't find out where the instances are initialized.

I would appreciate if you could help me with this matter.

@JonathanHuot
Copy link
Contributor

Hi, do you want to generate access_token as JWT ? If yes, please have a look at https://oauthlib.readthedocs.io/en/latest/oauth2/tokens/bearer.html

@KhashayarMirMS
Copy link
Author

Hi, yes I wanted to generate access token as JWT and I used the documentation you mentioned for the matter, my question can be related to this part of the documentation:
image
This initializes a new server object. But I couldn't find how to tell DOT to use this instance for it's OauthBackend instance.

@IvanAnishchuk
Copy link
Member

I think there are currently multiple places in the code where server instance is being initialized (three, if I remember correctly) and only one of them can be subclassed easily (OAuthLibCore.__init__). I think a good solution would be to add a settings option to allow passing custom kwargs to those server instances and maybe a couple specific settings for passing token_generator and refresh_token_generator there specifically (in a way that supports passing import strings in settings and perhaps making them classes that can accept parameters before being passed to server, client_id/client_secret generators are class-based and accept parameters, sounds like a usable pattern). This sounds like a small enough change that shouldn't break compatibility, let me see if I can fix a PR for this quickly....

Note however that you're likely to need to use a custom Server class anyway, sooner or later, if you want to customize anything regarding auth flow, You might as well start now, that's the simplest way to achieve what you need right now without updating the library.

IvanAnishchuk added a commit that referenced this issue Oct 19, 2019
Pass variables generated based on settings when initializing Server.
IvanAnishchuk added a commit that referenced this issue Oct 20, 2019
Pass variables generated based on settings when initializing Server.
IvanAnishchuk added a commit that referenced this issue Oct 23, 2019
Pass variables generated based on settings when initializing Server.
Add a property to settings class for convenience.
IvanAnishchuk added a commit that referenced this issue Oct 23, 2019
Pass variables generated based on settings when initializing Server.
Add a property to settings class for convenience.
Update settings documentation to reflect additions.
IvanAnishchuk added a commit that referenced this issue Oct 23, 2019
Pass variables generated based on settings when initializing Server.
Add a property to settings class for convenience.
Update settings documentation to reflect additions.
IvanAnishchuk added a commit that referenced this issue Oct 23, 2019
Pass variables generated based on settings when initializing Server.
Add a property to settings class for convenience.
Update settings documentation to reflect additions.
IvanAnishchuk added a commit that referenced this issue Oct 25, 2019
Pass variables generated based on settings when initializing Server.
Add a property to settings class for convenience.
Update settings documentation to reflect additions.
IvanAnishchuk added a commit that referenced this issue Oct 30, 2019
Pass variables generated based on settings when initializing Server.
Add a property to settings class for convenience.
Update settings documentation to reflect additions.
Fix tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants