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
Jérome Perrin
gitlab-ce
Commits
b45e9264
Commit
b45e9264
authored
Sep 04, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Gitlab::OAuth::User class
Authenticate or create users from OAuth providers
parent
cdc4d64d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
lib/gitlab/oauth/user.rb
lib/gitlab/oauth/user.rb
+85
-0
No files found.
lib/gitlab/oauth/user.rb
0 → 100644
View file @
b45e9264
# OAuth extension for User model
#
# * Find GitLab user based on omniauth uid and provider
# * Create new user from omniauth data
#
module
Gitlab
module
OAuth
class
User
class
<<
self
attr_reader
:auth
def
find
(
auth
)
@auth
=
auth
find_by_uid_and_provider
end
def
create
(
auth
)
@auth
=
auth
password
=
Devise
.
friendly_token
[
0
,
8
].
downcase
opts
=
{
extern_uid:
uid
,
provider:
provider
,
name:
name
,
username:
username
,
email:
email
,
password:
password
,
password_confirmation:
password
,
}
user
=
model
.
new
(
opts
,
as: :admin
).
with_defaults
user
.
save!
log
.
info
"(OAuth) Creating user
#{
email
}
from login with extern_uid =>
#{
uid
}
"
if
Gitlab
.
config
.
omniauth
[
'block_auto_created_users'
]
&&
!
ldap?
user
.
block
end
user
end
private
def
find_by_uid_and_provider
model
.
where
(
provider:
provider
,
extern_uid:
uid
).
last
end
def
uid
auth
.
info
.
uid
||
auth
.
uid
end
def
email
auth
.
info
.
email
.
downcase
unless
auth
.
info
.
email
.
nil?
end
def
name
auth
.
info
.
name
.
to_s
.
force_encoding
(
"utf-8"
)
end
def
username
email
.
match
(
/^[^@]*/
)[
0
]
end
def
provider
auth
.
provider
end
def
log
Gitlab
::
AppLogger
end
def
model
::
User
end
def
raise_error
(
message
)
raise
OmniAuth
::
Error
,
"(OAuth) "
+
message
end
def
ldap?
provider
==
'ldap'
end
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