Skip to content

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

Open
hoop33 wants to merge 6 commits into
plouc:masterfrom
hoop33:master
Open

Add session so you can log in and get token#18
hoop33 wants to merge 6 commits into
plouc:masterfrom
hoop33:master

Conversation

@hoop33

@hoop33 hoop33 commented Aug 6, 2015

Copy link
Copy Markdown

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

plouc commented Aug 7, 2015

Copy link
Copy Markdown
Owner

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

@hoop33

hoop33 commented Aug 7, 2015

Copy link
Copy Markdown
Author

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

plouc commented Aug 12, 2015

Copy link
Copy Markdown
Owner

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

@hoop33

hoop33 commented Aug 12, 2015

Copy link
Copy Markdown
Author

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

plouc commented Aug 12, 2015

Copy link
Copy Markdown
Owner

@hoop33, perhaps you should squash it

@plouc

plouc commented Apr 13, 2017

Copy link
Copy Markdown
Owner

@hoop33, can you please rebase this PR ?

@hoop33

hoop33 commented Apr 15, 2017

Copy link
Copy Markdown
Author

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