lib/gds-sso/warden_config.rb in gds-sso-0.3.0 vs lib/gds-sso/warden_config.rb in gds-sso-0.4.0
- old
+ new
@@ -39,10 +39,15 @@
::GDS::SSO::ApiAccess.api_call?(env)
end
def authenticate!
Rails.logger.debug("Authenticating with gds_sso_api_access strategy")
+
+ if ! basic_auth_configured?
+ Rails.logger.debug("Basic auth not configured, not requiring authentication")
+ success!('api')
+ end
auth = Rack::Auth::Basic::Request.new(env)
return custom!(unauthorized) unless auth.provided?
return fail!(:bad_request) unless auth.basic?
@@ -50,9 +55,13 @@
if valid_api_user?(*auth.credentials)
success!(auth.credentials[0])
else
custom!(unauthorized)
end
+ end
+
+ def basic_auth_configured?
+ ! ::GDS::SSO::Config.basic_auth_user.nil?
end
def valid_api_user?(username, password)
username.to_s.strip != '' &&
password.to_s.strip != '' &&