Skip to content
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

Merged
merged 4 commits into from
Feb 2, 2019
Merged

Conversation

yannvery
Copy link
Contributor

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 supports end_session_endpoint in discovery response.

For information I already use a fork of omniauth_openid_connect with openid_connect 1.1.6 on a rails app in production.

@@ -18,6 +18,63 @@ def test_request_phase
strategy.request_phase
end

def test_logout_phase_with_discovery
Copy link

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
Copy link

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$/
Copy link

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
Copy link

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
Copy link

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
Copy link

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]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5 (comment)

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)
Copy link

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
Copy link

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
Copy link

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.

@yannvery yannvery force-pushed the logout-endpoint branch 2 times, most recently from 1c2d23a to 4df356a Compare August 24, 2018 11:36
@@ -111,10 +111,25 @@ def callback_phase
fail!(:failed_to_connect, e)
end

def other_phase
if logout_path_pattern.match(current_path)
Copy link

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.

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?
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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)
Copy link
Collaborator

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

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. what's the point to pass config as argument?
  2. what's the point of extraction setup_client_options method? how does it pay for itself?
  3. 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

Copy link
Contributor Author

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.

@m0n9oose
Copy link
Collaborator

m0n9oose commented Jan 4, 2019

Please rebase your work branch on top of current master branch

@@ -18,6 +18,63 @@ def test_request_phase
strategy.request_phase
end

def test_logout_phase_with_discovery
Copy link

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
Copy link

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
Copy link

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
Copy link

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?
Copy link

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
Copy link

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)
Copy link

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
Copy link

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?
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5 (comment)

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.

@yannvery yannvery force-pushed the logout-endpoint branch 2 times, most recently from 7708f34 to 834a062 Compare February 1, 2019 19:01
@@ -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?
Copy link

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!
Copy link

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
Copy link

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?
Copy link

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?
Copy link

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
Copy link

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)
Copy link

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
Copy link

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.

@@ -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?
Copy link

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]

@yannvery
Copy link
Contributor Author

yannvery commented Feb 1, 2019

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.

@m0n9oose
Copy link
Collaborator

m0n9oose commented Feb 1, 2019 via email

@@ -18,6 +18,63 @@ def test_request_phase
strategy.request_phase
end

def test_logout_phase_with_discovery
Copy link

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
Copy link

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
Copy link

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
Copy link

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?
Copy link

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?
Copy link

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?
Copy link

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
Copy link

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)
Copy link

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
Copy link

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.

@m0n9oose m0n9oose merged commit 4c024ea into omniauth:master Feb 2, 2019
Eric-Guo pushed a commit to Eric-Guo/omniauth_openid_connect that referenced this pull request Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants