#3327 Getting username if authentication is done over API_TOKEN
Closed: Fixed Opened by phracek.

I have generated API_TOKEN, that's fine.
But If I want to check , that my PR already exist, then without username I am not able to get this information.
What about to get information about username from /api/0/whoami if I already have token
so I don't need to specify username.

Does it make sense to you?

Adding CC to @bkabrda


I'm not sure I fully understand the use-case here :(

Could you expand a little bit more?

Well, I have created token and I would like to check if my fork for specific repository already exists.

Via pagure API I would like to check api/0/fork/{user}/rpms/<repo>. But for this case I have only API_TOKEN and user is unknown.
Any way how to get the user?

Similar usercase is in OpenShift like oc whoami if token is specified.

The user is the user who forked the repo. So for your fork the user in the url will be: fork/phracel/rpms/.
If you want to see one of my work, you would have to access /fork/pingou/rpms/.

I'm not sure I see the full picture :(

Well, I have created a repo with

         data = {'namespace': self.namespace,
                     'repo': self.internal_repo,
                    'wait': True
                }
            r = requests.post(pagure_url + "/fork",
                              data=data,
                              headers={'Authorization': 'token {}'.format(self.get_conf_val('api_token'))},
                              verify=False,
                              )

You can see, no user is specified. Just API_TOKEN which is assigned to me for tests, but generally I don't know user name.

Next step is to clarify if the fork is really created by function:

   requests.get(pagure_url + '/fork/<user>/rpms/<repo>'

as you can see user has to be specified. This is fine.
But my question is, If I know only API_TOKEN, not the user, is there any way how to get username from API_TOKEN?

Hopefully now you can see the full picture.

Hopefully now you can see the full picture.

Thanks I do have a better picture now.

I does make me wonder though if we need a "whoamI" endpoint as you are describing or if the fork endpoint should return more information so that the question: "where is the repo I just created?" can be answered.

I'm a little bit inclined more towards the second. What do you think?

I think, whoami is better solution.
But the second option make sense to me if api_token provided by user and request

requests.get(pagure_url + '/fork/rpms/<repo>'

will return correct response like fork/<user>/rpms/<repo>

I still guess, getting user name from API_TOKEN is easier solution then "where is the repo I just created".

I think both are a good idea.
Both a whoami endpoint, and have the fork API return where your repo is if it already exists.
With the whoami, we could also add some additional information like which ssh keys and email addresses are registered. (though I'd say that to get those, the token would need to have a "userinfo" scope or something. But a general "what's my username" sounds like a good idea)

So you have any ET, when this could be implemented?
Like weeks, months ?

Metadata Update from @pingou:
- Issue assigned to pingou

Metadata Update from @pingou:
- Issue tagged with: RFE

PR up for review at: https://pagure.io/pagure/pull-request/3337

We can expand with the ideas @puiterwijk later on easily if we want :)

The PR looks good to me. Great.

Commit 48ad711c fixes this issue

Metadata
Related Pull Requests