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

Dynamic client_options.redirect_uri value #170

Open
Ksm125 opened this issue Dec 20, 2023 · 3 comments
Open

Dynamic client_options.redirect_uri value #170

Ksm125 opened this issue Dec 20, 2023 · 3 comments

Comments

@Ksm125
Copy link

Ksm125 commented Dec 20, 2023

There should be a way to have a dynamic value for the redirect_uri value as the app hostname is not known at the configuration level.

The default OmniAuth strategy uses the method callback_url for example.

full_host + callback_path + query_string

@mazoonit
Copy link

Hey, Did you get any luck with this ?

@Ksm125
Copy link
Author

Ksm125 commented Apr 2, 2024

Hey, Did you get any luck with this ?

@mazoonit yes, so i ended up just doing a monkey patch of the library with this :

module OmniAuth
  module Strategies
    # Override of the OpenIDConnect strategy to include the query string in the redirect_uri
    class OpenIDConnect
      # override of the redirect_uri method to include to dynamically detect the correct redirect_uri
      def redirect_uri
        callback_url
      end
    end
  end
end

@mazoonit
Copy link

mazoonit commented Apr 2, 2024

@Ksm125 Ended up doing the same yes to append custom state variable to the query string.
I used inheritance though because I used the plain OpenIDConnect in another connections so I tended not to directly patch It but after all It's the same Idea 👨🏻‍💻

module OmniAuth
    module Strategies
      class Custom < OmniAuth::Strategies::OpenIDConnect
        option :name, 'custom'
        def new_state
            state = if options.state.respond_to?(:call)
                      if options.state.arity == 1
                        options.state.call(env)
                      else
                        options.state.call
                      end
                    end
            if request.params['state']
                state = request.params['state']
            end
            session['omniauth.state'] = state || SecureRandom.hex(16)
        end
      end
    end
end

Thanks 🚀

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

No branches or pull requests

2 participants