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
0b5f80b4
Commit
0b5f80b4
authored
Sep 05, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle redirect URI query concatenation in a better way
parent
24411b6f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
10 deletions
+17
-10
app/controllers/oauth/jira/authorizations_controller.rb
app/controllers/oauth/jira/authorizations_controller.rb
+8
-9
spec/controllers/oauth/jira/authorizations_controller_spec.rb
.../controllers/oauth/jira/authorizations_controller_spec.rb
+9
-1
No files found.
app/controllers/oauth/jira/authorizations_controller.rb
View file @
0b5f80b4
...
...
@@ -14,8 +14,12 @@ class Oauth::Jira::AuthorizationsController < ActionController::Base
# 2. Handle the callback call as we were a Github Enterprise instance client.
def
callback
# TODO: join url params in a better way
redirect_to
(
session
[
'redirect_uri'
]
+
'&code='
+
params
[
:code
])
# Handling URI query params concatenation.
redirect_uri
=
URI
.
parse
(
session
[
'redirect_uri'
])
new_query
=
URI
.
decode_www_form
(
String
(
redirect_uri
.
query
))
<<
[
'code'
,
params
[
:code
]]
redirect_uri
.
query
=
URI
.
encode_www_form
(
new_query
)
redirect_to
redirect_uri
.
to_s
end
# 3. Rewire and adjust access_token request accordingly.
...
...
@@ -25,13 +29,8 @@ class Oauth::Jira::AuthorizationsController < ActionController::Base
.
merge
(
grant_type:
'authorization_code'
,
redirect_uri:
oauth_jira_callback_url
)
auth_response
=
HTTParty
.
post
(
oauth_token_url
,
body:
auth_params
)
token_type
,
scope
,
token
=
auth_response
[
'token_type'
],
auth_response
[
'scope'
],
auth_response
[
'access_token'
]
# TODO: join url params in a better way
token
=
"access_token="
+
auth_response
[
'access_token'
]
+
"&scope="
+
auth_response
[
'scope'
]
+
"&token_type="
+
auth_response
[
'token_type'
]
render
text:
token
render
text:
"access_token=
#{
token
}
&scope=
#{
scope
}
&token_type=
#{
token_type
}
"
end
end
spec/controllers/oauth/jira/authorizations_controller_spec.rb
View file @
0b5f80b4
...
...
@@ -13,6 +13,14 @@ describe Oauth::Jira::AuthorizationsController do
describe
'GET callback'
do
it
'redirects to redirect_uri on session with code param'
do
session
[
'redirect_uri'
]
=
'http://example.com'
get
:callback
,
code:
'hash-123'
expect
(
response
).
to
redirect_to
(
'http://example.com?code=hash-123'
)
end
it
'redirects to redirect_uri on session with code param preserving existing query'
do
session
[
'redirect_uri'
]
=
'http://example.com?foo=bar'
get
:callback
,
code:
'hash-123'
...
...
@@ -27,7 +35,7 @@ describe Oauth::Jira::AuthorizationsController do
'client_id'
=>
'client-123'
,
'client_secret'
=>
'secret-123'
,
'grant_type'
=>
'authorization_code'
,
'redirect_uri'
=>
'http://test.host/jira/login/oauth/callback'
}
'redirect_uri'
=>
'http://test.host/
-/
jira/login/oauth/callback'
}
expect
(
HTTParty
).
to
receive
(
:post
).
with
(
oauth_token_url
,
body:
expected_auth_params
)
do
{
'access_token'
=>
'fake-123'
,
'scope'
=>
'foo'
,
'token_type'
=>
'bar'
}
...
...
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