Skip to content

Implement autorization with new APIv2 token - #14

Open
MelvinFrederiks wants to merge 2 commits into
hashtopolis:mainfrom
MelvinFrederiks:improvement/token-auth
Open

Implement autorization with new APIv2 token#14
MelvinFrederiks wants to merge 2 commits into
hashtopolis:mainfrom
MelvinFrederiks:improvement/token-auth

Conversation

@MelvinFrederiks

Copy link
Copy Markdown

As far as i could tell is was not possible to authenticate with a new fine-grained apiv2 token in this API implementation. I've added basic support for this, so now you don't need to pass or store a password anymore if you are using this API.

If the config file contains both an api token and a username&password, opt for the api token.

Tested with_token with the following snippet:

$ python3
>>> import hashtopolis
>>> hashtopolis_url = '<hashtopolis_url>'
>>> token = '<token>'
>>> cfg = hashtopolis.HashtopolisConfig.with_token(hashtopolis_url, token)
>>> conn = hashtopolis.HashtopolisConnector('/ui/hashlists')
>>> conn.count(filter=None)
{'count': <count>}

Tested config file in the same way:

$ cat hashtopolis-test.yaml
hashtopolis_uri: '<hashtopolis_url>'
token: <token>
$ python3
>>> import hashtopolis
>>> cfg = hashtopolis.HashtopolisConfig()
>>> conn = hashtopolis.HashtopolisConnector('/ui/hashlists')
>>> conn.count(filter=None)
{'count': <count>}

This implementation does not validate the token upon creation of the HashtopolisConfig object, so an incorrect token will not raise an error until the first actual API call is made. However this currently also happens when authenticating with a password.

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

Successfully merging this pull request may close these issues.

1 participant