Zverik / cli-oauth2

Helper library for OAuth2 in command-line tools
https://pypi.org/project/cli-oauth2/
Apache License 2.0
11 stars 2 forks source link

Add GitlabAuth & ForgejoAuth providers & make tokens storage modular #1

Open brenard opened 4 months ago

brenard commented 4 months ago

Hello,

In a new project, I need to handle Gitlab OAuth2 from CLI and I was happy to find your lib. I add support for Gitlab that does not support urn:ietf:wg:oauth:2.0:oob redirect URI so I also add a redirect_uri parameter to AuthFlow.auth_code().

Furthermore, I don't want to store tokens in my case and I think it's could be great to have possibilty to store tokens in a more secure way. So, I create a modular way to store token: I keep your method as default and adding two new storage backends:

To use one of them, we just have to provide one instance of them by using the tokens_storage parameter of the provider:

auth = GitlabAuth(
    client_id,
    secret_id,
    ['read_user'],
    url=server_url,
    tokens_storage=KeyringStorage() ,
)

The storage backend constructor allow to customize their behaviour, so I add some parameters:

Edit: I also added Forgejo auth provider too. It may be also compatible with Gitea.