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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
8c6e9eb0
Commit
8c6e9eb0
authored
Mar 08, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More refactor to Geo Authentication with OAuth
parent
d39a9b2f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
36 deletions
+47
-36
app/controllers/oauth/geo_auth_controller.rb
app/controllers/oauth/geo_auth_controller.rb
+2
-2
app/models/geo/oauth_session.rb
app/models/geo/oauth_session.rb
+0
-33
app/models/geo/remote_node.rb
app/models/geo/remote_node.rb
+44
-0
config/application.rb
config/application.rb
+1
-1
No files found.
app/controllers/oauth/geo_auth_controller.rb
View file @
8c6e9eb0
...
...
@@ -18,7 +18,7 @@ class Oauth::GeoAuthController < ActionController::Base
end
token
=
oauth
.
get_token
(
params
[
:code
],
redirect_uri:
oauth_geo_callback_url
)
remote_user
=
oauth
.
authenticate
(
access_token:
token
)
remote_user
=
Geo
::
RemoteNode
.
new
.
authenticate
(
token
)
user
=
User
.
find
(
remote_user
[
'id'
])
...
...
@@ -27,7 +27,7 @@ class Oauth::GeoAuthController < ActionController::Base
redirect_to
(
return_to
||
root_path
)
else
@error
=
'Invalid credentials'
render
:
new
render
:
error
end
end
...
...
app/models/geo/oauth_session.rb
View file @
8c6e9eb0
class
Geo::OauthSession
include
ActiveModel
::
Model
include
HTTParty
attr_accessor
:state
attr_accessor
:return_to
API_PREFIX
=
'/api/v3/'
def
is_oauth_state_valid?
return
true
unless
state
salt
,
hmac
,
return_to
=
state
.
split
(
':'
,
3
)
...
...
@@ -25,15 +22,6 @@ class Geo::OauthSession
state
.
split
(
':'
,
3
)[
2
]
if
state
end
def
authenticate
(
access_token
)
opts
=
{
query:
access_token
}
response
=
self
.
class
.
get
(
authenticate_endpoint
,
default_opts
.
merge
(
opts
))
build_response
(
response
)
end
def
authorize_url
(
params
=
{})
oauth_client
.
auth_code
.
authorize_url
(
params
)
end
...
...
@@ -73,28 +61,7 @@ class Geo::OauthSession
Gitlab
::
Geo
.
oauth_authentication
end
def
authenticate_endpoint
File
.
join
(
primary_node_url
,
API_PREFIX
,
'user'
)
end
def
primary_node_url
Gitlab
::
Geo
.
primary_node
.
url
end
def
default_opts
{
headers:
{
'Content-Type'
=>
'application/json'
},
}
end
def
build_response
(
response
)
case
response
.
code
when
200
response
.
parsed_response
when
401
raise
UnauthorizedError
else
nil
end
end
end
app/models/geo/remote_node.rb
0 → 100644
View file @
8c6e9eb0
class
Geo::RemoteNode
class
UnauthorizedError
<
StandardError
end
include
HTTParty
API_PREFIX
=
'/api/v3/'
def
authenticate
(
access_token
)
opts
=
{
query:
{
access_token:
access_token
}
}
response
=
self
.
class
.
get
(
authenticate_endpoint
,
default_opts
.
merge
(
opts
))
build_response
(
response
)
end
private
def
authenticate_endpoint
File
.
join
(
primary_node_url
,
API_PREFIX
,
'user'
)
end
def
primary_node_url
Gitlab
::
Geo
.
primary_node
.
url
end
def
default_opts
{
headers:
{
'Content-Type'
=>
'application/json'
},
}
end
def
build_response
(
response
)
case
response
.
code
when
200
response
.
parsed_response
when
401
raise
UnauthorizedError
else
nil
end
end
end
config/application.rb
View file @
8c6e9eb0
...
...
@@ -95,7 +95,7 @@ module Gitlab
ENV
[
'GITLAB_PATH_OUTSIDE_HOOK'
]
=
ENV
[
'PATH'
]
# Gitlab Geo Middleware support
config
.
middleware
.
use
'Gitlab::Middleware::ReadonlyGeo'
config
.
middleware
.
insert_after
ActionDispatch
::
Flash
,
'Gitlab::Middleware::ReadonlyGeo'
config
.
generators
do
|
g
|
g
.
factory_girl
false
...
...
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