Skip to content

Commit 5df6b0b

Browse files
author
Robert Speicher
committed
Merge branch 'facebook-auth' into 'master'
Add Facebook authentication See merge request !1740
2 parents 3f05c22 + 05eb9e7 commit 5df6b0b

File tree

12 files changed

+125
-14
lines changed

12 files changed

+125
-14
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ v 8.2.0 (unreleased)
2626
v 8.1.3
2727
- Spread out runner contacted_at updates
2828
- New design for user profile page
29+
- Add Facebook authentication
2930

3031
v 8.1.1
3132
- Fix cloning Wiki repositories via HTTP (Stan Hu)

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ gem 'devise-async', '~> 0.9.0'
1919
gem 'doorkeeper', '~> 2.1.3'
2020
gem 'omniauth', '~> 1.2.2'
2121
gem 'omniauth-bitbucket', '~> 0.0.2'
22+
gem 'omniauth-facebook', '~> 3.0.0'
2223
gem 'omniauth-github', '~> 1.1.1'
2324
gem 'omniauth-gitlab', '~> 1.0.0'
2425
gem 'omniauth-google-oauth2', '~> 0.2.0'

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ GEM
423423
multi_json (~> 1.7)
424424
omniauth (~> 1.1)
425425
omniauth-oauth (~> 1.0)
426+
omniauth-facebook (3.0.0)
427+
omniauth-oauth2 (~> 1.2)
426428
omniauth-github (1.1.2)
427429
omniauth (~> 1.0)
428430
omniauth-oauth2 (~> 1.1)
@@ -859,6 +861,7 @@ DEPENDENCIES
859861
octokit (~> 3.7.0)
860862
omniauth (~> 1.2.2)
861863
omniauth-bitbucket (~> 0.0.2)
864+
omniauth-facebook (~> 3.0.0)
862865
omniauth-github (~> 1.1.1)
863866
omniauth-gitlab (~> 1.0.0)
864867
omniauth-google-oauth2 (~> 0.2.0)
2.9 KB
Loading

app/helpers/auth_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module AuthHelper
2-
PROVIDERS_WITH_ICONS = %w(twitter github gitlab bitbucket google_oauth2).freeze
2+
PROVIDERS_WITH_ICONS = %w(twitter github gitlab bitbucket google_oauth2 facebook).freeze
33
FORM_BASED_PROVIDERS = [/\Aldap/, 'crowd'].freeze
44

55
def ldap_enabled?

config/gitlab.yml.example

+12-11
Original file line numberDiff line numberDiff line change
@@ -274,27 +274,28 @@ production: &base
274274
# arguments, followed by optional 'args' which can be either a hash or an array.
275275
# Documentation for this is available at http://doc.gitlab.com/ce/integration/omniauth.html
276276
providers:
277-
# - { name: 'google_oauth2',
278-
# label: 'Google',
279-
# app_id: 'YOUR_APP_ID',
280-
# app_secret: 'YOUR_APP_SECRET',
281-
# args: { access_type: 'offline', approval_prompt: '' } }
282-
# - { name: 'twitter',
283-
# app_id: 'YOUR_APP_ID',
284-
# app_secret: 'YOUR_APP_SECRET' }
285277
# - { name: 'github',
286-
# label: 'GitHub',
287278
# app_id: 'YOUR_APP_ID',
288279
# app_secret: 'YOUR_APP_SECRET',
289280
# args: { scope: 'user:email' } }
281+
# - { name: 'bitbucket',
282+
# app_id: 'YOUR_APP_ID',
283+
# app_secret: 'YOUR_APP_SECRET' }
290284
# - { name: 'gitlab',
291-
# label: 'GitLab.com',
292285
# app_id: 'YOUR_APP_ID',
293286
# app_secret: 'YOUR_APP_SECRET',
294287
# args: { scope: 'api' } }
295-
# - { name: 'bitbucket',
288+
# - { name: 'google_oauth2',
289+
# app_id: 'YOUR_APP_ID',
290+
# app_secret: 'YOUR_APP_SECRET',
291+
# args: { access_type: 'offline', approval_prompt: '' } }
292+
# - { name: 'facebook',
296293
# app_id: 'YOUR_APP_ID',
297294
# app_secret: 'YOUR_APP_SECRET' }
295+
# - { name: 'twitter',
296+
# app_id: 'YOUR_APP_ID',
297+
# app_secret: 'YOUR_APP_SECRET' }
298+
#
298299
# - { name: 'saml',
299300
# label: 'Our SAML Provider',
300301
# args: {

doc/integration/facebook.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Facebook OAuth2 OmniAuth Provider
2+
3+
To enable the Facebook OmniAuth provider you must register your application with Facebook. Facebook will generate an app ID and secret key for you to use.
4+
5+
1. Sign in to the [Facebook Developer Platform](https://developers.facebook.com/).
6+
7+
1. Choose "My Apps" > "Add a New App"
8+
9+
1. Select the type "Website"
10+
11+
1. Enter a name for your app. This can be anything. Consider something like "<Organization>'s GitLab" or "<Your Name>'s GitLab" or
12+
something else descriptive.
13+
14+
1. Choose "Create New Facebook App ID"
15+
16+
1. Select a Category, for example "Productivity"
17+
18+
1. Choose "Create App ID"
19+
20+
1. Enter the address of your GitLab installation at the bottom of the package
21+
22+
![Facebook Website URL](facebook_website_url.png)
23+
24+
1. Choose "Next"
25+
26+
1. Choose "Skip Quick Start" in the upper right corner
27+
28+
1. Choose "Settings" in the menu on the left
29+
30+
1. Fill in a contact email for your app
31+
32+
![Facebook App Settings](facebook_app_settings.png)
33+
34+
1. Choose "Save Changes"
35+
36+
1. Choose "Status & Review" in the menu on the left
37+
38+
1. Change the switch on the right from No to Yes
39+
40+
1. Choose "Confirm" when prompted to make the app public
41+
42+
1. Choose "Dashboard" in the menu on the left
43+
44+
1. Choose "Show" next to the hidden "App Secret"
45+
46+
1. You should now see an app key and app secret (see screenshot). Keep this page open as you continue configuration.
47+
48+
![Facebook API Keys](facebook_api_keys.png)
49+
50+
1. On your GitLab server, open the configuration file.
51+
52+
For omnibus package:
53+
54+
```sh
55+
sudo editor /etc/gitlab/gitlab.rb
56+
```
57+
58+
For installations from source:
59+
60+
```sh
61+
cd /home/git/gitlab
62+
63+
sudo -u git -H editor config/gitlab.yml
64+
```
65+
66+
1. See [Initial OmniAuth Configuration](omniauth.md#initial-omniauth-configuration) for initial settings.
67+
68+
1. Add the provider configuration:
69+
70+
For omnibus package:
71+
72+
```ruby
73+
gitlab_rails['omniauth_providers'] = [
74+
{
75+
"name" => "facebook",
76+
"app_id" => "YOUR_APP_ID",
77+
"app_secret" => "YOUR_APP_SECRET"
78+
}
79+
]
80+
```
81+
82+
For installations from source:
83+
84+
```
85+
- { name: 'facebook', app_id: 'YOUR_APP_ID',
86+
app_secret: 'YOUR_APP_SECRET' }
87+
```
88+
89+
1. Change 'YOUR_APP_ID' to the API key from Facebook page in step 10.
90+
91+
1. Change 'YOUR_APP_SECRET' to the API secret from the Facebook page in step 10.
92+
93+
1. Save the configuration file.
94+
95+
1. Restart GitLab for the changes to take effect.
96+
97+
On the sign in page there should now be a Facebook icon below the regular sign in form. Click the icon to begin the authentication process. Facebook will ask the user to sign in and authorize the GitLab application. If everything goes well the user will be returned to GitLab and will be signed in.

doc/integration/facebook_api_keys.png

123 KB
Loading
131 KB
Loading
41.3 KB
Loading

doc/integration/omniauth.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ Now we can choose one or more of the Supported Providers below to continue confi
7373
- [Bitbucket](bitbucket.md)
7474
- [GitLab.com](gitlab.md)
7575
- [Google](google.md)
76-
- [Shibboleth](shibboleth.md)
76+
- [Facebook](facebook.md)
7777
- [Twitter](twitter.md)
78+
- [Shibboleth](shibboleth.md)
7879
- [SAML](saml.md)
7980
- [Crowd](crowd.md)
8081

lib/gitlab/o_auth/provider.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module Gitlab
22
module OAuth
33
class Provider
4+
LABELS = {
5+
"github" => "GitHub",
6+
"gitlab" => "GitLab.com",
7+
"google_oauth2" => "Google"
8+
}.freeze
9+
410
def self.providers
511
Devise.omniauth_providers
612
end
@@ -23,8 +29,9 @@ def self.config_for(name)
2329
end
2430

2531
def self.label_for(name)
32+
name = name.to_s
2633
config = config_for(name)
27-
(config && config['label']) || name.to_s.titleize
34+
(config && config['label']) || LABELS[name] || name.titleize
2835
end
2936
end
3037
end

0 commit comments

Comments
 (0)