# GitLab OmniAuth plugin

**URL:** https://meta.discourse.org/t/gitlab-omniauth-plugin/24382
**Category:** Plugin
**Tags:** auth-plugins
**Created:** [January 24, 2015, 12:52am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382 "2015-01-24T00:52:41Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [January 24, 2015, 12:52am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/1 "2015-01-24T00:52:41Z")

</div>

Source code: [GitLab.org / discourse-omniauth-gitlab · GitLab](https://gitlab.com/gitlab-org/discourse-omniauth-gitlab)

> ⚠ **Attention**
> 
> This is supported on GitLab 7.7+.

## Installation

First, register a new system application in GitLab by visiting `/admin/applications/new`.  
The redirect URI is of the form:

```plaintext
https://discourse.example.com/auth/gitlab/callback

```

Add the plugin’s repository url to your container’s `app.yml` file:

```plaintext
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://gitlab.com/gitlab-org/discourse-omniauth-gitlab.git

```

Rebuild the container by providing the APP\_ID, SECRET and GitLab url values:

```plaintext
cd /var/discourse
git pull origin master
GITLAB_APP_ID=gitlabtestid GITLAB_SECRET=gitlabtestsecret GITLAB_URL=https://git.example.com ./launcher rebuild app

```

Otherwise you can add these variables in `app.yml` under the `env` section.

 ![](https://global.discourse-cdn.com/meta/original/3X/c/1/c118b4da08f7042f19489777f05093ecbdd71413.png)

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [April 9, 2015, 4:24pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/2 "2015-04-09T16:24:55Z")

</div>

I have a silly question: you mention `/admin/applications/new`, but my Gitlab instance returns 404 for this URL. Any idea what could cause this? (Omnibus 7.5.3) I couldn’t find anything relative to that problem here or in Gitlab’s forum (and I don’t have console access to troubleshoot it).

---

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [April 9, 2015, 5:35pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/3 "2015-04-09T17:35:27Z")

</div>

Not silly at all, my fault I didn’t mention it. This is supported on 7.7+.

[https://about.gitlab.com/2015/01/22/gitlab-7-7-and-ci-5-4-released/](https://about.gitlab.com/2015/01/22/gitlab-7-7-and-ci-5-4-released/)

---

<div class="post-metadata">

### Author: ![ephemeraleclipse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ephemeraleclipse/32/116929_2.png) [@ephemeraleclipse](https://meta.discourse.org/u/ephemeraleclipse)
#### Post date: [October 21, 2015, 1:43pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/4 "2015-10-21T13:43:01Z")

</div>

Hey I realize this is a very old topic now, but this plugin is really interesting. This is exactly what I’m looking for but I’m just curious about how the existing discourse users will be connected to Gitlab account.  
For example, Gitlab’s OAuth allows a logged in user to connect their Google, Facebook, or Github accounts in their settings, is there something similar in this plugin for discourse to gitlab as well?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [October 21, 2015, 8:20pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/5 "2015-10-21T20:20:54Z")

</div>

> [@ephemeraleclipse](#):
>
> Hey I realize this is a very old topic now, but this plugin is really interesting. This is exactly what I’m looking for but I’m just curious about how the existing discourse users will be connected to Gitlab account.

It will be by the email provided by Gitlab. If the email matches when you first sign in with Gitlab, the account will be connected.

---

<div class="post-metadata">

### Author: ![ephemeraleclipse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ephemeraleclipse/32/116929_2.png) [@ephemeraleclipse](https://meta.discourse.org/u/ephemeraleclipse)
#### Post date: [October 21, 2015, 8:35pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/6 "2015-10-21T20:35:46Z")

</div>

orly? Thanks very much! 😃 can’t wait to try it out tonight

---

<div class="post-metadata">

### Author: ![ephemeraleclipse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ephemeraleclipse/32/116929_2.png) [@ephemeraleclipse](https://meta.discourse.org/u/ephemeraleclipse)
#### Post date: [October 29, 2015, 3:01pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/7 "2015-10-29T15:01:19Z")

</div>

~~it’s not connecting the account, when I try to log in with gitlab it just redirects me to signup with my info filled out and tells me my username and email has already been taken ☹~~

Got it fixed, made a merge request to the repo on gitlab, not sure if anyone still maintains that o\_o

---

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [October 30, 2015, 12:22am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/8 "2015-10-30T00:22:19Z")

</div>

Yes, I maintain it and merged your MR thanks!

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [February 25, 2016, 5:30pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/9 "2016-02-25T17:30:41Z")

</div>

Hello,

I have manually created accounts that I want to associate with a Gitlab account. Is there a way to do it?

The normal workflow is that an existing gitlab account visits the Discourse: then its discourse account is created. What I want to do is, as an admin or as the logged-in user, explicitly set the link between the gitlab and discourse accounts.

---

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [February 26, 2016, 7:35pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/10 "2016-02-26T19:35:08Z")

</div>

I guess setting the same e-mail between GitLab and Discourse will work.

---

<div class="post-metadata">

### Author: ![RalfJung](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ralfjung/32/51654_2.png) [@RalfJung](https://meta.discourse.org/u/RalfJung)
#### Post date: [February 26, 2016, 9:49pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/11 "2016-02-26T21:49:09Z")

</div>

Yes - if you log in via GitLab and there already is a Discourse account with that e-mail address, then that’s the account you are logged in to.

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [February 28, 2016, 3:02am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/12 "2016-02-28T03:02:13Z")

</div>

@RalfJung my experiment doesn’t match your description: I tried logging in with my gitlab account which uses the same username and email as the existing Discourse account.

But when I “login with gitlab”, I receive a proposal to **create a new account** named `username1` instead of the existing `username`.

What you describe is what I would like to achieve. Moreover, I’d like to have a user UI to associate an account. This, it seems to me, is missing from the current Discourse.

---

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [February 28, 2016, 7:20am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/13 "2016-02-28T07:20:33Z")

</div>

Are you pulling the latest master? There was a change back in October which fixed the issue you describe [added ability to connect existing accounts (2b2016eb) · Commits · GitLab.org / discourse-omniauth-gitlab · GitLab](https://gitlab.com/gitlab-org/discourse-omniauth-gitlab/commit/2b2016eb78cee326dd1f6a6ff3b66c0dd46d50e5)

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [February 28, 2016, 12:49pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/14 "2016-02-28T12:49:57Z")

</div>

Hmmm, my plugin page was showing a fixed version (`v0.0.2`) without any mean to change it nor update the plugin. I ran again the rebuild command:

> [@axil](#):
>
> GITLAB\_APP\_ID=gitlabtestid GITLAB\_SECRET=gitlabtestsecret GITLAB\_URL=[https://git.example.com](https://git.example.com) ./launcher rebuild app

No change: [Imgur: The magic of the Internet](http://imgur.com/VwSIDuX)

[Edit:] Seems like [GitLab.org / omniauth-gitlab · GitLab](https://gitlab.com/gitlab-org/omniauth-gitlab) is DEPRECATED. The page tells to look at [GitHub - linchus/omniauth-gitlab: Strategy for authenticating to your GitLab service · GitHub](https://github.com/linchus/omniauth-gitlab) instead. Should I use that, or your fork?

---

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [February 29, 2016, 7:24am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/15 "2016-02-29T07:24:22Z")

</div>

The Discourse plugin uses `linchus/omniauth-gitlab`, not my fork, see [plugin.rb · master · GitLab.org / discourse-omniauth-gitlab · GitLab](https://gitlab.com/gitlab-org/discourse-omniauth-gitlab/blob/master/plugin.rb#L6)

I [bumped](https://gitlab.com/gitlab-org/discourse-omniauth-gitlab/commit/02e0481634a95c632d568096b36a9aeedddfb211) the version to 0.0.3 to include a fix in `omniauth-gitlab` ([https://github.com/linchus/omniauth-gitlab/issues/10](https://github.com/linchus/omniauth-gitlab/issues/10)). Try to rebuild the container.

Although it’s strange, because we use the same version as you in [https://forum.gitlab.com](https://forum.gitlab.com) and works fine, I just tested it.

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [February 29, 2016, 9:42am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/16 "2016-02-29T09:42:42Z")

</div>

I rebuilt the instance and now it shows `v0.0.3`. But I still can’t login from Gitlab: it proposes me to use a different username. This is weird.

I tried running the code from the console:

```ruby
::PluginStore.get("gl", "gl_uid_hellekin")
=> nil
existing_user = User.where(email: email).first
=> User ...
::PluginStore.set("gl", "gl_uid_hellekin", {user_id: existing_user.id})

```

Then tried to login from gitlab again. No luck.

BTW, I submitted an MR to fix a minor issue.

---

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [February 29, 2016, 9:59am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/17 "2016-02-29T09:59:02Z")

</div>

Could it be that you have multiple e-mails in GitLab? I think it only captures the one you set as primary.

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [February 29, 2016, 10:18am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/18 "2016-02-29T10:18:47Z")

</div>

I have emails using `+`, e.g., `user+foo@example.org`. Would that interfere?

---

<div class="post-metadata">

### Author: ![axil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axil/32/81682_2.png) [@axil](https://meta.discourse.org/u/axil)
#### Post date: [February 29, 2016, 10:27am UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/19 "2016-02-29T10:27:24Z")

</div>

No, but i tried with a new GitLab account and I can reproduce your issue. Investigating.

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [March 14, 2016, 5:08pm UTC](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382/20 "2016-03-14T17:08:27Z")

</div>

Any progress on this @axil?

[Next page](https://meta.discourse.org/t/gitlab-omniauth-plugin/24382.md?page=2)
