Skip to content

Add session so you can log in and get token #18

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hoop33
Copy link

@hoop33 hoop33 commented Aug 6, 2015

Apologies if this exists and I just didn't see it -- this allows users to log in:

gitlab := gogitlab.NewGitlab(url, "/api/v3", "")
session, err := gitlab.NewSession(userId, "", password)
if err == nil {
  gitlab.Token = session.PrivateToken
  // Now you can call gitlab.Projects() or whatever
}

@plouc
Copy link
Owner

plouc commented Aug 7, 2015

@hoop33 there was a similar PR /pull/11 which has been closed in favor of oauth2 which is now supported by gitlab.

@hoop33
Copy link
Author

hoop33 commented Aug 7, 2015

I can understand that, and I see that GitLab supports OAuth2 without the webflow (http://doc.gitlab.com/ce/api/oauth2.html#resource-owner-password-credentials) -- I'm writing a command-line application, so avoiding the webflow is important. Configuring OAuth2 for GitLab seems onerous, though (https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/integration/google.md) -- perhaps including this as an option, with comments to indicate that OAuth2 is usually preferred?

@plouc
Copy link
Owner

plouc commented Aug 12, 2015

@hoop33, I know it's not really up-to-date but can you please update the README ? thx

@hoop33
Copy link
Author

hoop33 commented Aug 12, 2015

Sorry for the multiple commits--it took me a bit to figure out the tab following the asterisk to get the formatting right. I can squash the commits if you'd like.

@plouc
Copy link
Owner

plouc commented Aug 12, 2015

@hoop33, perhaps you should squash it

@plouc
Copy link
Owner

plouc commented Apr 13, 2017

@hoop33, can you please rebase this PR ?

@hoop33
Copy link
Author

hoop33 commented Apr 15, 2017

I rebased it (local machine -- haven't pushed it up), then did some testing, and I think we'd be better off closing it for the following reasons:

  1. It's a POST but with form data, so would have to either change the execRequest or execRequestRaw function not to automatically add the Content-Type header, or would have to write a new function that doesn't add it. I get a 400 unless I remove that header. I tried formatting the params as JSON before calling buildAndExecuteRequest, but I still get a 400.
  2. The session API is now deprecated (and disabled for users with TFA): https://docs.gitlab.com/ce/api/session.html
  3. GitLab has added personal tokens, so the workflow I've adopted in my CLIs is to instruct people to create a token through the website, and then run:
$ <app> login
Please paste your token:

Thoughts?

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.

2 participants