Skip to content
Snippets Groups Projects
Commit cfc22309 authored by Achilleas Pipinellis's avatar Achilleas Pipinellis
Browse files

Init commit.

parents
No related branches found
No related tags found
No related merge requests found
LICENSE 0 → 100644
The MIT License (MIT)
Copyright (c) 2015 GitLab B.V.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
discourse-omniauth-gitlab
=========================
Discourse plugin for the omniauth-gitlab strategy.
## Installation
1. Add the plugin's repository url to your container's `app.yml` file:
```
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
```
1. Rebuild the container by providing the ID and SECRET values:
```
cd /var/discourse
git pull origin master
GITLAB_APP_ID=gitlabtestid GITLAB_SECRET=gitlabtestsecret GITLAB_SITE_URL=https://git.example.com ./launcher rebuild app
```
Otherwise you can provide these variables in `app.yml` under the `env` section.
## License
MIT, see [LICENSE](./LICENSE).
# name: discourse-omniauth-gitlab
# about: Authenticate Discourse with GitLab
# version: 0.0.1
# author: Achilleas Pipinellis
require 'omniauth2-gitlab'
class GitLabAuthenticator < ::Auth::Authenticator
GITLAB_APP_ID = ENV['GITLAB_APP_ID']
GITLAB_SECRET = ENV['GITLAB_SECRET']
def name
'gitlab'
end
def after_authenticate(auth_token)
result = Auth::Result.new
# Grap the info we need from OmniAuth
data = auth_token[:info]
name = data["first_name"]
gl_uid = auth_token["uid"]
email = data['email']
# Plugin specific data storage
current_info = ::PluginStore.get("gl", "gl_uid_#{gl_uid}")
result.user =
if current_info
User.where(id: current_info[:user_id]).first
end
result.name = name
result.extra_data = { gl_uid: gl_uid }
result.email = email
result
end
def after_create_account(user, auth)
data = auth[:extra_data]
::PluginStore.set("gl", "gl_uid_#{data[:gl_uid]}", {user_id: user.id })
end
def register_middleware(omniauth)
omniauth.provider :gitlab,
GITLAB_APP_ID,
GITLAB_SECRET,
{ client_options: {site: ENV['GITLAB_SITE_URL'], }}
end
end
auth_provider :title => 'with GitLab',
:message => 'Log in via GitLab (Make sure pop up blockers are not enabled).',
:frame_width => 920,
:frame_height => 800,
:authenticator => GitLabAuthenticator.new
# We ship with zocial, it may have an icon you like http://zocial.smcllns.com/sample.html
# In our current case we don't have an icon for GitLab
register_css <<CSS
.btn-social.gitlab {
background: #554488;
}
.btn-social.gitlab:before {
content: "G";
}
CSS
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment