lib/gds-sso/warden_config.rb in gds-sso-2.0.0 vs lib/gds-sso/warden_config.rb in gds-sso-2.0.1

- old
+ new

@@ -1,8 +1,15 @@ require 'warden' require 'gds-sso/user' +def logger + if Rails.logger # if we are actually running in a rails app + Rails.logger + else + env['rack.logger'] + end +end Warden::Manager.after_authentication do |user, auth, opts| # We've successfully signed in. # If they were remotely signed out, clear the flag as they're no longer suspended user.clear_remotely_signed_out! @@ -30,11 +37,11 @@ def valid? ! ::GDS::SSO::ApiAccess.api_call?(env) end def authenticate! - Rails.logger.debug("Authenticating with gds_sso strategy") + logger.debug("Authenticating with gds_sso strategy") if request.env['omniauth.auth'].nil? fail!("No credentials, bub") else user = prep_user(request.env['omniauth.auth']) @@ -56,11 +63,11 @@ ::GDS::SSO::ApiAccess.api_call?(env) && ::GDS::SSO::ApiAccess.oauth_api_call?(env) end def authenticate! - Rails.logger.debug("Authenticating with gds_bearer_token strategy") + logger.debug("Authenticating with gds_bearer_token strategy") begin access_token = OAuth2::AccessToken.new(oauth_client, token_from_authorization_header) response_body = access_token.get('/user.json').body user_details = omniauth_style_response(response_body) @@ -135,11 +142,11 @@ def valid? ::GDS::SSO::ApiAccess.api_call?(env) end def authenticate! - Rails.logger.debug("Authenticating with gds_sso_api_access strategy") + logger.debug("Authenticating with gds_sso_api_access strategy") auth = Rack::Auth::Basic::Request.new(env) return custom!(unauthorized) unless auth.provided? return fail!(:bad_request) unless auth.basic? @@ -175,11 +182,11 @@ def valid? ! ::GDS::SSO::ApiAccess.api_call?(env) end def authenticate! - Rails.logger.warn("Authenticating with mock_gds_sso strategy") + logger.warn("Authenticating with mock_gds_sso strategy") test_user = GDS::SSO.test_user test_user ||= ENV['GDS_SSO_MOCK_INVALID'].present? ? nil : GDS::SSO::Config.user_klass.first if test_user # Brute force ensure test user has correct perms to signin @@ -202,9 +209,9 @@ def valid? ::GDS::SSO::ApiAccess.api_call?(env) end def authenticate! - Rails.logger.debug("Authenticating with mock_gds_sso_api_access strategy") + logger.debug("Authenticating with mock_gds_sso_api_access strategy") success!(GDS::SSO::ApiUser.new) end end