Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
redmine-oauth
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyECP
redmine-oauth
Commits
a7c4fd2c
Commit
a7c4fd2c
authored
Oct 31, 2012
by
Дмитрий Коваленок
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
functional testing
parent
fc430d6e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
6 deletions
+108
-6
app/controllers/redmine_oauth_controller.rb
app/controllers/redmine_oauth_controller.rb
+71
-0
app/controllers/redmine_omniauth_controller.rb
app/controllers/redmine_omniauth_controller.rb
+5
-3
app/views/hooks/_view_account_login_bottom.html.erb
app/views/hooks/_view_account_login_bottom.html.erb
+1
-1
config/routes.rb
config/routes.rb
+2
-2
test/functional/redmine_oauth_controller_test.rb
test/functional/redmine_oauth_controller_test.rb
+29
-0
No files found.
app/controllers/redmine_oauth_controller.rb
0 → 100644
View file @
a7c4fd2c
require
'account_controller'
require
'json'
class
RedmineOauthController
<
AccountController
def
oauth_google
redirect_to
oauth_client
.
auth_code
.
authorize_url
(
redirect_uri:
oauth_google_callback_url
,
scope:
scopes
)
end
def
oauth_google_callback
token
=
oauth_client
.
auth_code
.
get_token
(
params
[
:code
],
redirect_uri:
oauth_google_callback_url
)
result
=
token
.
get
(
'https://www.googleapis.com/oauth2/v1/userinfo'
)
info
=
JSON
.
parse
(
result
.
body
)
if
info
&&
info
[
"verified_email"
]
user
=
User
.
find_or_initialize_by_mail
(
info
[
"email"
])
if
user
.
new_record?
# Self-registration off
redirect_to
(
home_url
)
&&
return
unless
Setting
.
self_registration?
# Create on the fly
user
.
firstname
,
user
.
lastname
=
info
[
"name"
].
split
(
' '
)
unless
info
[
'name'
].
nil?
user
.
firstname
||=
info
[
:given_name
]
user
.
lastname
||=
info
[
:family_name
]
user
.
mail
=
info
[
"email"
]
login
=
info
[
"email"
].
match
(
/(.+)@/
)
unless
info
[
"email"
].
nil?
user
.
login
=
login
[
1
]
if
login
user
.
login
||=
[
user
.
firstname
,
user
.
lastname
]
*
"."
user
.
random_password
user
.
register
case
Setting
.
self_registration
when
'1'
register_by_email_activation
(
user
)
do
onthefly_creation_failed
(
user
)
end
when
'3'
register_automatically
(
user
)
do
onthefly_creation_failed
(
user
)
end
else
register_manually_by_administrator
(
user
)
do
onthefly_creation_failed
(
user
)
end
end
else
# Existing record
if
user
.
active?
successful_authentication
(
user
)
else
account_pending
end
end
else
flash
[
:error
]
=
l
(
:notice_unable_to_obtain_google_credentials
)
redirect_to
signin_path
end
end
def
oauth_client
@client
||=
OAuth2
::
Client
.
new
(
settings
[
:client_id
],
settings
[
:client_secret
],
site:
'https://accounts.google.com'
,
authorize_url:
'/o/oauth2/auth'
,
token_url:
'/o/oauth2/token'
)
end
def
settings
@settings
||=
Setting
.
plugin_redmine_omniauth_google
end
def
scopes
'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
end
end
\ No newline at end of file
app/controllers/redmine_omniauth_controller.rb
View file @
a7c4fd2c
require
'account_controller'
require
'json'
class
RedmineOmniauthController
<
AccountController
def
omniauth_google
class
RedmineOauthController
<
AccountController
def
oauth_google
ds
redirect_to
oauth_client
.
auth_code
.
authorize_url
(
redirect_uri:
oauth_google_callback_url
,
scope:
scopes
)
end
def
oauth_google_callback
token
=
oauth_client
.
auth_code
.
get_token
(
params
[
:code
],
redirect_uri:
oauth_google_callback_url
)
result
=
token
.
get
(
'https://www.googleapis.com/oauth2/v1/userinfo'
)
binding
.
pr
info
=
JSON
.
parse
(
result
.
body
)
if
info
[
"verified_email"
]
if
info
&&
info
[
"verified_email"
]
user
=
User
.
find_or_initialize_by_mail
(
info
[
"email"
])
if
user
.
new_record?
# Self-registration off
...
...
app/views/hooks/_view_account_login_bottom.html.erb
View file @
a7c4fd2c
<%
if
Setting
.
openid?
%>
<%=
link_to
image_tag
(
'/plugin_assets/redmine_omniauth_google/images/google_login_icon.jpg'
),
o
mniauth_google_path
(
openid_url:
'google.com'
)
%>
<%=
link_to
image_tag
(
'/plugin_assets/redmine_omniauth_google/images/google_login_icon.jpg'
),
o
auth_google_path
%>
<%
end
%>
\ No newline at end of file
config/routes.rb
View file @
a7c4fd2c
get
'omniauth_google'
,
to:
'redmine_omniauth#omniauth_google'
,
as: :omniauth_google
get
'oauth_google_callback'
,
to:
'redmine_omniauth#oauth_google_callback'
\ No newline at end of file
get
'oauth_google'
,
to:
'redmine_oauth#oauth_google'
get
'oauth_google_callback'
,
to:
'redmine_oauth#oauth_google_callback'
\ No newline at end of file
test/functional/redmine_oauth_controller_test.rb
0 → 100644
View file @
a7c4fd2c
require
File
.
expand_path
(
'../../test_helper'
,
__FILE__
)
class
RedmineOauthControllerTest
<
ActionController
::
TestCase
def
setup
User
.
current
=
nil
Setting
.
openid
=
'1'
OAuth2
::
AccessToken
.
any_instance
.
stubs
(
get:
OAuth2
::
Response
.
new
(
nil
))
OAuth2
::
Client
.
any_instance
.
stubs
(
get_token:
OAuth2
::
AccessToken
.
new
(
'code'
,
'redirect_uri'
))
end
def
set_response_body_stub
body
OAuth2
::
Response
.
any_instance
.
stubs
(
body:
body
.
to_json
)
end
def
test_login_with_omniauth_for_new_user
Setting
.
self_registration
=
'3'
user_credentials
=
{
:firstname
=>
'Cool'
,
:lastname
=>
'User'
,
:mail
=>
'user@somedomain.com'
}
User
.
where
(
user_credentials
).
delete_all
new_user
=
User
.
new
(
user_credentials
)
new_user
.
login
=
'cool_user'
set_response_body_stub
({
verified_email:
"true"
,
name:
[
new_user
.
firstname
,
new_user
.
lastname
]
*
" "
,
given_name:
new_user
.
firstname
,
family_name:
new_user
.
lastname
,
email:
new_user
.
mail
})
get
:oauth_google_callback
,
:email
=>
new_user
.
mail
assert_redirected_to
controller:
'my'
,
action:
'account'
end
#assert existing_user.save!
end
\ No newline at end of file
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