go-gitlab-client icon indicating copy to clipboard operation
go-gitlab-client copied to clipboard

Add session so you can log in and get token

Open hoop33 opened this issue 9 years ago • 7 comments

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
}

hoop33 avatar Aug 06 '15 21:08 hoop33

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

plouc avatar Aug 07 '15 08:08 plouc

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?

hoop33 avatar Aug 07 '15 12:08 hoop33

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

plouc avatar Aug 12 '15 06:08 plouc

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.

hoop33 avatar Aug 12 '15 12:08 hoop33

@hoop33, perhaps you should squash it

plouc avatar Aug 12 '15 12:08 plouc

@hoop33, can you please rebase this PR ?

plouc avatar Apr 13 '17 07:04 plouc

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?

hoop33 avatar Apr 15 '17 13:04 hoop33