Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab API - How to get private_token using GET with session parameter?

I am using GitLab API v3 to do some operations on my private installation. Using private_token in GET URL is working fine. e.g.

GET http://git.example.com/api/v3/projects?=private_token=xyz123

But in order to make this possible, you need a private_token. There is one sure way to get it - from your account settings. But I want my users to use their email id/ login id and password to retrieve the private key and use it from there for rest of the operations.

I used following GET url and it is doing nothing for me:

GET http://git.example.com/api/v3/session?login=xyzuser&password=xyzpassword

Ideally as per GitLab documentation, I should get a JSON as follows -

{
  "id": 1,
  "username": "john_smith",
  "email": "[email protected]",
  "name": "John Smith",
  "private_token": "dd34asd13as",
  "blocked": false,
  "created_at": "2012-05-23T08:00:58Z",
  "bio": null,
  "skype": "",
  "linkedin": "",
  "twitter": "",
  "dark_scheme": false,
  "theme_id": 1,
  "is_admin": false,
  "can_create_group" : true,
  "can_create_team" : true,
  "can_create_project" : true
}

If I get this, I can get private_token and work from there.

What am I doing wrong?

like image 378
Amar Gautam Avatar asked Dec 02 '13 16:12

Amar Gautam


People also ask

How do I get my GitLab API token?

To locate your personal GitLab API key, first navigate to the GitLab User Settings from the main menu. Then click on Access Tokens in the left side menu. Give a descriptive name for your token, select the “api” scope and finally click on the Create personal access token button.

Where is my GitLab API URL?

To authorise access to the GitLab API, you need to provide the base URL of your GitLab instance. If you're a GitLab.com user, the base URL is https://gitlab.com .


1 Answers

You need to POST the data as stated in the api (http://api.gitlab.org/session.html).

Be aware that if you do this action on a http port (instead of using https) that the password is send in plain text to the server.

like image 176
Jacob Struiksma Avatar answered Oct 01 '22 09:10

Jacob Struiksma