Could someone help explain the new feature to allow auth providers to provide a custom URL? I tried to read through the code but didn’t really understand what was happening. Any insight would be great — thanks!
committed 05:19PM - 20 Apr 16 UTC
I believe it’s used in the SAML auth provider if that’s any help to you:
request_method = GlobalSetting.try(:saml_request_method) || 'get'
class SamlAuthenticator < ::Auth::OAuth2Authenticator
def register_middleware(omniauth)
omniauth.provider :saml,
:name => 'saml',
:issuer => 'discourse',
:idp_sso_target_url => GlobalSetting.saml_target_url,
:idp_cert_fingerprint => GlobalSetting.try(:saml_cert_fingerprint),
:custom_url => (GlobalSetting.try(:saml_request_method) == 'post') ? "/discourse_saml" : nil
end
def after_authenticate(auth)
result = Auth::Result.new
uid = auth[:uid]
result.username = uid
result.email = uid
result.email_valid = true
title = GlobalSetting.try(:saml_title) || "SAML"
button_title = GlobalSetting.try(:saml_title) || "with SAML"
auth_provider :title => button_title,
:authenticator => SamlAuthenticator.new('saml'),
:message => "Authorizing with #{title} (make sure pop up blockers are not enabled)",
:frame_width => 600,
:frame_height => 380,
:background_color => '#003366',
:custom_url => request_method == 'post' ? "/discourse_saml" : nil
1 Like
Should we clarify in the settings copy if this is for saml only @eviltrout ?
It’s not a site setting though, that’s an internal field that plugin authors can use to set a custom URL.
As to how to use it, any plugin that creates an omniauth.provider can supply a :custom_url if they like like in the SAML example above.
4 Likes