-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RP-Initiated Logout phase #5
Conversation
@@ -18,6 +18,63 @@ def test_request_phase | |||
strategy.request_phase | |||
end | |||
|
|||
def test_logout_phase_with_discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for test_logout_phase_with_discovery is too high. [33.38/15]
@@ -18,6 +18,63 @@ def test_request_phase | |||
strategy.request_phase | |||
end | |||
|
|||
def test_logout_phase_with_discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [16/10]
@@ -18,6 +18,63 @@ def test_request_phase | |||
strategy.request_phase | |||
end | |||
|
|||
def test_logout_phase_with_discovery | |||
expected_redirect = /^https:\/\/example\.com\/logout$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use %r
around regular expression.
strategy.other_phase | ||
end | ||
|
||
def test_logout_phase_with_discovery_and_post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for test_logout_phase_with_discovery_and_post_logout_redirect_uri is too high. [34.53/15]
strategy.other_phase | ||
end | ||
|
||
def test_logout_phase_with_discovery_and_post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [17/10]
@@ -111,10 +113,27 @@ def callback_phase | |||
fail!(:failed_to_connect, e) | |||
end | |||
|
|||
def other_phase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for other_phase is too high. [15.56/15]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why but this thread marked as "outdated". Anyways, I'm totally fine with your latest suggestion. Apply it and we're good to go.
@@ -235,6 +255,19 @@ def redirect_uri | |||
"#{ client_options.redirect_uri }?redirect_uri=#{ CGI.escape(request.params['redirect_uri']) }" | |||
end | |||
|
|||
def encoded_post_logout_redirect_uri | |||
return unless options.post_logout_redirect_uri | |||
URI.encode_www_form(post_logout_redirect_uri: options.post_logout_redirect_uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [87/80]
end | ||
|
||
def end_session_endpoint_is_valid? | ||
client_options.end_session_endpoint && client_options.end_session_endpoint =~ URI.regexp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [96/80]
end | ||
|
||
def end_session_endpoint_is_valid? | ||
client_options.end_session_endpoint && client_options.end_session_endpoint =~ URI.regexp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URI.regexp
is obsolete and should not be used. Instead, use URI::DEFAULT_PARSER.make_regexp
.
1c2d23a
to
4df356a
Compare
@@ -111,10 +111,25 @@ def callback_phase | |||
fail!(:failed_to_connect, e) | |||
end | |||
|
|||
def other_phase | |||
if logout_path_pattern.match(current_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use match?
instead of match
when MatchData
is not used.
0873500
to
92ed82c
Compare
client_options.userinfo_endpoint = config.userinfo_endpoint | ||
client_options.jwks_uri = config.jwks_uri | ||
return unless options.discovery | ||
options.issuer = issuer if options.issuer.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am i right in assumption issuer
won't be set if discovery
disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Discovery issuer
will be only used only discovery
is enabled and options issuer
was blank?
Another point, I'm wondering if you prefer that I avoid using rails blank?
method here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Discovery issuer will be only used only discovery is enabled and options issuer was blank?
Is this intentional change? Old code has different behaviour, I'm not sure about this.
Another point, I'm wondering if you prefer that I avoid using rails blank? method here.
Yeah, good point, it'd be great to avoid rails' methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I get it. You're right I've modified the behavior around the issuer.
Well it's not the purpose of the PR, so I've decided to keep the original implementation.
@@ -111,10 +111,25 @@ def callback_phase | |||
fail!(:failed_to_connect, e) | |||
end | |||
|
|||
def other_phase | |||
if logout_path_pattern.match(current_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider the following changes:
def other_phase
return call_app! unless logout_path_pattern.match(current_path)
discover!
redirect(end_session_uri) if end_session_uri
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call_app!
must be called when end_session_uri
is falsy
I could change as the following (could be harder to read with multiple return
and call_app!
calls)
def other_phase
return call_app! unless logout_path_pattern.match(current_path)
discover!
return redirect(end_session_uri) if end_session_uri
call_app!
end
client_options.jwks_uri = config.jwks_uri | ||
return unless options.discovery | ||
options.issuer = issuer if options.issuer.blank? | ||
setup_client_options(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- what's the point to pass
config
as argument? - what's the point of extraction
setup_client_options
method? how does it pay for itself? - please avoid using Rails methods in gems which can be used outside of Rails project (
try
)
Consider the following changes:
def discover!
return unless options.discovery
client_options.authorization_endpoint = config.authorization_endpoint
client_options.token_endpoint = config.token_endpoint
client_options.userinfo_endpoint = config.userinfo_endpoint
client_options.jwks_uri = config.jwks_uri
client_options.end_session_endpoint = config.end_session_endpoint if config.respond_to?(:end_session_endpoint)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree, I can't explain why I did that.
Thanks for your feedback.
Please rebase your work branch on top of current |
92ed82c
to
96b97fe
Compare
@@ -18,6 +18,63 @@ def test_request_phase | |||
strategy.request_phase | |||
end | |||
|
|||
def test_logout_phase_with_discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for test_logout_phase_with_discovery is too high. [33.38/15]
@@ -18,6 +18,63 @@ def test_request_phase | |||
strategy.request_phase | |||
end | |||
|
|||
def test_logout_phase_with_discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [16/10]
strategy.other_phase | ||
end | ||
|
||
def test_logout_phase_with_discovery_and_post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for test_logout_phase_with_discovery_and_post_logout_redirect_uri is too high. [34.53/15]
strategy.other_phase | ||
end | ||
|
||
def test_logout_phase_with_discovery_and_post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [17/10]
def authorization_code | ||
request.params['code'] | ||
end | ||
|
||
def end_session_uri | ||
return unless end_session_endpoint_is_valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
@@ -143,10 +158,13 @@ def issuer | |||
end | |||
|
|||
def discover! | |||
return unless options.discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
client_options.authorization_endpoint = config.authorization_endpoint | ||
client_options.token_endpoint = config.token_endpoint | ||
client_options.userinfo_endpoint = config.userinfo_endpoint | ||
client_options.jwks_uri = config.jwks_uri | ||
client_options.end_session_endpoint = config.end_session_endpoint if config.respond_to?(:end_session_endpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [118/80]
@@ -235,6 +253,22 @@ def redirect_uri | |||
"#{ client_options.redirect_uri }?redirect_uri=#{ CGI.escape(request.params['redirect_uri']) }" | |||
end | |||
|
|||
def encoded_post_logout_redirect_uri | |||
return unless options.post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
client_options.userinfo_endpoint = config.userinfo_endpoint | ||
client_options.jwks_uri = config.jwks_uri | ||
return unless options.discovery | ||
options.issuer = issuer if options.issuer.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Discovery issuer will be only used only discovery is enabled and options issuer was blank?
Is this intentional change? Old code has different behaviour, I'm not sure about this.
Another point, I'm wondering if you prefer that I avoid using rails blank? method here.
Yeah, good point, it'd be great to avoid rails' methods.
@@ -111,10 +113,27 @@ def callback_phase | |||
fail!(:failed_to_connect, e) | |||
end | |||
|
|||
def other_phase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why but this thread marked as "outdated". Anyways, I'm totally fine with your latest suggestion. Apply it and we're good to go.
7708f34
to
834a062
Compare
@@ -96,8 +98,8 @@ def callback_phase | |||
elsif !request.params['code'] | |||
return fail!(:missing_code, OmniAuth::OpenIDConnect::MissingCodeError.new(request.params['error'])) | |||
else | |||
options.issuer = issuer if options.issuer.blank? | |||
discover! if options.discovery | |||
options.issuer = issuer if options.issuer.nil? || options.issuer.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 0) spaces for indentation.
options.issuer = issuer if options.issuer.blank? | ||
discover! if options.discovery | ||
options.issuer = issuer if options.issuer.nil? || options.issuer.empty? | ||
discover! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation detected.
@@ -111,10 +113,26 @@ def callback_phase | |||
fail!(:failed_to_connect, e) | |||
end | |||
|
|||
def other_phase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for other_phase is too high. [16.52/15]
@@ -111,10 +113,26 @@ def callback_phase | |||
fail!(:failed_to_connect, e) | |||
end | |||
|
|||
def other_phase | |||
if logout_path_pattern.match?(current_path) | |||
options.issuer = issuer if options.issuer.nil? || options.issuer.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
def authorization_code | ||
request.params['code'] | ||
end | ||
|
||
def end_session_uri | ||
return unless end_session_endpoint_is_valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
@@ -143,10 +161,12 @@ def issuer | |||
end | |||
|
|||
def discover! | |||
return unless options.discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
client_options.authorization_endpoint = config.authorization_endpoint | ||
client_options.token_endpoint = config.token_endpoint | ||
client_options.userinfo_endpoint = config.userinfo_endpoint | ||
client_options.jwks_uri = config.jwks_uri | ||
client_options.end_session_endpoint = config.end_session_endpoint if config.respond_to?(:end_session_endpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [118/80]
@@ -235,6 +255,22 @@ def redirect_uri | |||
"#{ client_options.redirect_uri }?redirect_uri=#{ CGI.escape(request.params['redirect_uri']) }" | |||
end | |||
|
|||
def encoded_post_logout_redirect_uri | |||
return unless options.post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
834a062
to
694fc90
Compare
@@ -96,8 +98,8 @@ def callback_phase | |||
elsif !request.params['code'] | |||
return fail!(:missing_code, OmniAuth::OpenIDConnect::MissingCodeError.new(request.params['error'])) | |||
else | |||
options.issuer = issuer if options.issuer.blank? | |||
discover! if options.discovery | |||
options.issuer = issuer if options.issuer.nil? || options.issuer.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
Sorry, for the delay of my response. |
Yeah, makes sense
…--
Best regards,
Ilia Shcherbinin
On 1 February 2019 at 20:08:53, Yann VERY ***@***.***) wrote:
Sorry, for the delay of my response.
I prefer to not fix all the bot issues and avoid making too many
modifications in 1 PR.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABaPnOoaDB8lYlnNn7aLPVO_FCurtW2Xks5vJJDFgaJpZM4WLDk5>
.
|
@@ -18,6 +18,63 @@ def test_request_phase | |||
strategy.request_phase | |||
end | |||
|
|||
def test_logout_phase_with_discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for test_logout_phase_with_discovery is too high. [33.38/15]
@@ -18,6 +18,63 @@ def test_request_phase | |||
strategy.request_phase | |||
end | |||
|
|||
def test_logout_phase_with_discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [16/10]
strategy.other_phase | ||
end | ||
|
||
def test_logout_phase_with_discovery_and_post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for test_logout_phase_with_discovery_and_post_logout_redirect_uri is too high. [34.53/15]
strategy.other_phase | ||
end | ||
|
||
def test_logout_phase_with_discovery_and_post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [17/10]
@@ -99,8 +101,8 @@ def callback_phase | |||
elsif !params['code'] | |||
return fail!(:missing_code, OmniAuth::OpenIDConnect::MissingCodeError.new(params['error'])) | |||
else | |||
options.issuer = issuer if options.issuer.blank? | |||
discover! if options.discovery | |||
options.issuer = issuer if options.issuer.nil? || options.issuer.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
@@ -114,10 +116,26 @@ def callback_phase | |||
fail!(:failed_to_connect, e) | |||
end | |||
|
|||
def other_phase | |||
if logout_path_pattern.match?(current_path) | |||
options.issuer = issuer if options.issuer.nil? || options.issuer.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
def authorization_code | ||
params['code'] | ||
end | ||
|
||
def end_session_uri | ||
return unless end_session_endpoint_is_valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
@@ -148,10 +166,12 @@ def issuer | |||
end | |||
|
|||
def discover! | |||
return unless options.discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
client_options.authorization_endpoint = config.authorization_endpoint | ||
client_options.token_endpoint = config.token_endpoint | ||
client_options.userinfo_endpoint = config.userinfo_endpoint | ||
client_options.jwks_uri = config.jwks_uri | ||
client_options.end_session_endpoint = config.end_session_endpoint if config.respond_to?(:end_session_endpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [118/80]
@@ -240,6 +260,22 @@ def redirect_uri | |||
"#{ client_options.redirect_uri }?redirect_uri=#{ CGI.escape(params['redirect_uri']) }" | |||
end | |||
|
|||
def encoded_post_logout_redirect_uri | |||
return unless options.post_logout_redirect_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line after guard clause.
Bump openid_connect to 1.1.6
Hello,
Here is an implementation of the logout phase initiated by the RP.
The relative spec:
http://openid.net/specs/openid-connect-session-1_0.html#RPLogout
I've also updated
openid_connect
dependency to 1.1.6 which supportsend_session_endpoint
in discovery response.For information I already use a fork of
omniauth_openid_connect
withopenid_connect
1.1.6 on a rails app in production.