go-gitlab-client
go-gitlab-client copied to clipboard
Add session so you can log in and get token
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 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.
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, I know it's not really up-to-date but can you please update the README ? thx
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, perhaps you should squash it
@hoop33, can you please rebase this PR ?
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:
- 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.
- The session API is now deprecated (and disabled for users with TFA): https://docs.gitlab.com/ce/api/session.html
- 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?