Skip to content

Commit fd13de9

Browse files
committed
Use API v4 by default
1 parent bcf52ae commit fd13de9

2 files changed

Lines changed: 35 additions & 18 deletions

File tree

README.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,35 @@ Or install it yourself as:
3131
## Standalone Usage
3232

3333
use OmniAuth::Builder do
34-
provider :gitlab, ENV['GITLAB_KEY'], ENV['GITLAB_SECRET'],
35-
client_options: {
36-
site: 'https://gitlab.YOURDOMAIN.com',
37-
authorize_url: '/oauth/authorize',
38-
token_url: '/oauth/token'
39-
}
34+
provider :gitlab, ENV['GITLAB_KEY'], ENV['GITLAB_SECRET'],
35+
{
36+
client_options: {
37+
site: 'https://gitlab.YOURDOMAIN.com/api/v4'
38+
}
39+
}
40+
end
41+
42+
## Custom scopes
43+
44+
use OmniAuth::Builder do
45+
provider :gitlab, ENV['GITLAB_KEY'], ENV['GITLAB_SECRET'], scope: 'read_user openid'
46+
end
47+
48+
## Old API version
49+
50+
API V3 will be unsupported from GitLab 9.5 and will be removed in GitLab 9.5 or later.
51+
52+
[https://gitlab.com/help/api/v3_to_v4.md](https://gitlab.com/help/api/v3_to_v4.md)
53+
54+
If you use GitLab 9.0 and below you could configure V3 API:
55+
56+
use OmniAuth::Builder do
57+
provider :gitlab, ENV['GITLAB_KEY'], ENV['GITLAB_SECRET'],
58+
{
59+
client_options: {
60+
site: 'https://gitlab.YOURDOMAIN.com/api/v3'
61+
}
62+
}
4063
end
4164

4265
## Contributing

lib/omniauth/strategies/gitlab.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,18 @@
44
module OmniAuth
55
module Strategies
66
class GitLab < OmniAuth::Strategies::OAuth2
7-
8-
option :client_options, {
9-
site: 'https://gitlab.com',
10-
authorize_url: '/oauth/authorize',
11-
token_url: '/oauth/token'
12-
}
7+
option :client_options, site: 'https://gitlab.com/api/v4'
138

149
option :redirect_url
1510

1611
uid { raw_info['id'].to_s }
1712

1813
info do
1914
{
20-
name: raw_info['name'],
21-
username: raw_info['username'],
22-
email: raw_info['email'],
23-
image: raw_info['avatar_url']
15+
name: raw_info['name'],
16+
username: raw_info['username'],
17+
email: raw_info['email'],
18+
image: raw_info['avatar_url']
2419
}
2520
end
2621

@@ -29,7 +24,7 @@ class GitLab < OmniAuth::Strategies::OAuth2
2924
end
3025

3126
def raw_info
32-
@raw_info ||= access_token.get('/api/v3/user').parsed
27+
@raw_info ||= access_token.get('user').parsed
3328
end
3429

3530
private
@@ -41,5 +36,4 @@ def callback_url
4136
end
4237
end
4338

44-
4539
OmniAuth.config.add_camelization 'gitlab', 'GitLab'

0 commit comments

Comments
 (0)