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

Allow username and password to be passed to Connection object #16

Open
astrofrog opened this issue Apr 29, 2015 · 4 comments
Open

Allow username and password to be passed to Connection object #16

astrofrog opened this issue Apr 29, 2015 · 4 comments

Comments

@astrofrog
Copy link
Contributor

... as an alternative to the API token. I can try and open a pull request if you like.

@rliebz
Copy link
Contributor

rliebz commented Apr 30, 2015

As far as I know, support has been dropped for username/password authentication in favor of API tokens in Dataverse 4.0 (see http://guides.dataverse.org/en/latest/api/sword.html#backward-incompatible-changes). The client in its current state is very 3.X incompatible, but I could point you to the last 3.6 compatible commit that still accepted usernames/passwords if you are trying to work with an older installation.

@astrofrog
Copy link
Contributor Author

Actually I was referring more to the new native API which allows one to get the API token from the username and password. This could happen seamlessly inside the Connection object, right? In my mini-Python library I do:

LOGIN_URL = "https://{server}/api/builtin-users/{username}/api-token?password={password}"

class Connection(object):

    def __init__(self, username=None, password=None, api_token=None, server=None):

        self.server = server
        self.username = username

        if username is not None:
            if password is None:
                raise ValueError("password is not set")
            url = LOGIN_URL.format(server=server, username=username, password=password)
            response = requests.get(url).json()
            self.api_token = parse_response(response)['message']
        else:
            self.api_token = api_token

@rliebz
Copy link
Contributor

rliebz commented Apr 30, 2015

Yeah, that works.

The only issue that could come up is that currently, you have to generate the API token through the GUI before you can retrieve it through the API, but with good error handling that shouldn't be a problem. If this is something you would use, feel free to open a PR.

@pdurbin
Copy link
Member

pdurbin commented Apr 30, 2015

currently, you have to generate the API token through the GUI before you can retrieve it through the API

Right. See also IQSS/dataverse#1935

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