omniauth / omniauth_openid_connect

MIT License
168 stars 187 forks source link

Dynamic client_options.redirect_uri value #170

Open Ksm125 opened 9 months ago

Ksm125 commented 9 months ago

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 commented 6 months ago

Hey, Did you get any luck with this ?

Ksm125 commented 6 months ago

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 commented 6 months ago

@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 🚀