Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
a2ef52b3
Commit
a2ef52b3
authored
Aug 22, 2016
by
Douglas Barbosa Alexandre
Committed by
Stan Hu
Nov 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom OmniAuth strategy for Bitbucket OAuth2
parent
69aaa972
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
config/initializers/omniauth.rb
config/initializers/omniauth.rb
+6
-0
lib/omniauth/strategies/bitbucket.rb
lib/omniauth/strategies/bitbucket.rb
+45
-0
No files found.
config/initializers/omniauth.rb
View file @
a2ef52b3
...
...
@@ -26,3 +26,9 @@ if Gitlab.config.omniauth.enabled
end
end
end
module
OmniAuth
module
Strategies
autoload
:Bitbucket
,
Rails
.
root
.
join
(
'lib'
,
'omniauth'
,
'strategies'
,
'bitbucket'
)
end
end
lib/omniauth/strategies/bitbucket.rb
0 → 100644
View file @
a2ef52b3
require
'omniauth-oauth2'
module
OmniAuth
module
Strategies
class
Bitbucket
<
OmniAuth
::
Strategies
::
OAuth2
option
:name
,
'bitbucket'
option
:client_options
,
{
site:
'https://bitbucket.org'
,
authorize_url:
'https://bitbucket.org/site/oauth2/authorize'
,
token_url:
'https://bitbucket.org/site/oauth2/access_token'
}
def
callback_url
full_host
+
script_name
+
callback_path
end
uid
do
raw
[
'username'
]
end
info
do
{
name:
raw_info
[
'display_name'
],
avatar:
raw_info
[
'links'
][
'avatar'
][
'href'
],
email:
primary_email
}
end
def
raw_info
@raw_info
||=
access_token
.
get
(
'user'
).
parsed
end
def
primary_email
primary
=
emails
.
find
{
|
i
|
i
[
'is_primary'
]
&&
i
[
'is_confirmed'
]
}
primary
&&
primary
[
'email'
]
||
nil
end
def
emails
email_response
=
access_token
.
get
(
'user/emails'
).
parsed
@emails
||=
email_response
&&
email_response
[
'values'
]
||
nil
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment