Using Gitlab API, integrating gitlab in django project for authentication and access

This is a simple way to integrate gitlab authentication in your django apps.

We can get user verified email id, general information, git lab URL and token from Gitlab API.

These Following steps are needed for Gitlab integration:

  • 1. creating git lab app
  • 2. Authenticating user and getting an access token.
  • 3. Get user information, git lab URL using an access token.

1. Creating Gitlab App

a. To create an app, Go to your profile and click on applications then create an application on top of a page.

Here you can give your application name, redirect URLs then the application will be created.

b. Now you can get the client id, secret of an application

2. Authenticating user and getting an access token.

a. Here We have to create a GET request for asking user permission.

GET http://{{Your GIT_LAB_DOMAIN }}/oauth/authorize?client_id={{ Your GIT_LAB_APP_ID }} &redirect_uri={{ redirect_uri }}&response_type=code"

GIT_LAB_DOMAIN: your git lab domain,

GIT_LAB_APP_ID: your application client id,

REDIRECT_URI: The URL which you want to redirect after user login and this URL must be set in the

app registered redirected URLs.

b. If an user accepts the permissions, then authorization code will be sent to redirected URL.

c. Then we get an access token from the JSON response with the post request and the following params.

          params = {

                'grant_type': 'authorization_code',

                'client_id': {{ Your Application id }},

                'redirect_uri': {{ Your Redirect }}

                'client_secret': {{ Your GIT_APP_SECRET }},

               'code': request.GET.get('code')


  POST  "http://{{ GIT_LAB_DOMAIN }}/oauth/token"

3. Get user information with get request using access token.

  params = { "access_token": {{ access_token }},}  
  GET  rty = "http://{{ GIT_LAB_DOMAIN }}/api/v3/user"

You can get the user git lab url, picture, email, name, currently sign at, created at etc values. from the JSON response.

Posted On 25 February 2016 By MicroPyramid

Need any Help in your Project?Let's Talk

Latest Comments
Is Django best framework for your web application development

Is Django best framework for your web application development

Continue Reading...
How to maintain user session across sub domains in Django

Nowadays, people are using wildcard domains to provide same user experience across different domains. Using subdomains, we can be able to host multiple sites with …

Continue Reading...
What is Django CRM and it’s advantages

Here in this blog you can find about CRM, Importance of CRM in sales, Types of CRM, How django crm helps for business and it’s …

Continue Reading...
Implementation of single sign on using auth0 in django application

As the no of applications increases, users need to create username & passwords, need to remember for each application. Users can't remember these details and, …

Continue Reading...
Customizing Django REST API Serializers

Customizing Django REST API Serializers

Continue Reading...

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties