sdoxsee / omniauth-oidc

Strategy to authenticate with OpenID Connect in OmniAuth.
5 stars 2 forks source link

Question about dynamically setting options? #2

Open wennerma opened 4 years ago

wennerma commented 4 years ago

Is there a strategy for setting up the provider options dynamically when called? I was trying to implement something like this within my initializer below.

Rails.application.config.middleware.use(OmniAuth::Builder) do

  SETUP_PROC = lambda do |env|
    req = Rack::Request.new(env)
    provider = ProviderFinder.find_by_subdomain(req.subdomain)
    # Google example:
    # provider.name = :google
    # provider.site = 'https://oauth2.googleapis.com'
    # provider.authorize_url = 'https://accounts.google.com/o/oauth2/auth'
    # provider.redirect_uri = 'https://mysite.com'
    # provider.client_id = client_id
    # provider.client_secret = client_secret

    env['omniauth.strategy'].options[:name] = provider.name
    env['omniauth.strategy'].options[:scope] = 'openid profile email offline_access'
    env['omniauth.strategy'].options[:site] = provider.site
    env['omniauth.strategy'].options[:authorize_url] = provider.authorize_url
    env['omniauth.strategy'].options[:client_id] = provider.client_id
    env['omniauth.strategy'].options[:client_secret] = provider.client_secret
    env['omniauth.strategy'].options[:redirect_uri] = provider.redirect_uri
  end

  provider :oidc, setup: SETUP_PROC

end
sdoxsee commented 4 years ago

Hi @wennerma. I'm not actively working on this project but if you'd like to submit a PR that you're comfortable with, I'd be happy to merge it in. Thanks!