app/controllers/auth_controller.rb
# omniauth callback on failure (login was started from rails)
# oauth_failure is also used if user cancels authorization/login
omniauth callback on failure (login was started from rails)
oauth_failure is also used if user cancels authorization/login
omniauth callback on failure ( login was started from rails ) oauth_failure is also used if user cancels authorization / login
def oauth_failure
    env = request.env
    error = env['omniauth.error']
    type = env['omniauth.error.type']
    strategy = env['omniauth.error.strategy']
    logger.debug2  "error = #{error} (#{error.class})"
    logger.debug2  "error.methods = #{error.methods.sort.join(', ')}"
    logger.debug2  "error.message = #{error.message} (#{error.message.class})"
    request_uri = env['REQUEST_URI']
    uri_prefix = "#{SITE_URL}auth/facebook/callback?error"
    if request_uri.first(uri_prefix.length) == uri_prefix and
        type == :invalid_credentials and
        error.class == OmniAuth::Strategies::OAuth2::CallbackError and
        params[:error] == 'access_denied'
      logger.debug2  "facebook login was cancelled"
      save_flash_key ".login_cancelled", :provider => 'facebook', :appname => APP_NAME
      redirect_to :controller => :auth
      return
    end
    type = env['omniauth.error.type']
    if request_uri == "#{SITE_URL}auth/linkedin/callback" and
        type == :invalid_credentials and
        error.class == OAuth::Problem and
        error.message == 'parameter_absent'
      client = get_linkedin_api_client()
      if client
        logger.debug2  "request for linked rw_nus priv. was cancelled"
        save_flash_key ".linkedin_rw_nus_cancelled", :appname => APP_NAME
        redirect_to :controller => :gifts
      else
        logger.debug2  "linkedin login was cancelled"
        save_flash_key ".login_cancelled", :provider => 'linkedin', :appname => APP_NAME
        redirect_to :controller => :auth
      end
      return
    end
    logger.debug2  "request_uri = #{request_uri}"
    logger.debug2  "type = #{type} (#{type.class})"
    logger.debug2  "error.class = #{error.class}"
    logger.debug2  "error.message = #{error.message}"
    uri_prefix = "#{SITE_URL}auth/twitter/callback?denied="
    if request_uri.first(uri_prefix.length) == uri_prefix and
        type == :invalid_credentials and
        error.class == OAuth::Unauthorized and
        error.message == '401 Unauthorized'
      logger.debug2  "twitter login was cancelled"
      save_flash_key ".login_cancelled", :provider => 'twitter', :appname => APP_NAME
      redirect_to :controller => :auth
      return
    end
    message = $1 if error.message =~ /"message": "(.*?)"/
    message = error.message unless message
    message = message.to_s.first(40)
    save_flash_key '.authentication_failure', :provider => provider_downcase(strategy.name), :type => type, :message => message
    redirect_to '/auth'
  end
def oauth_failure env = request . env error = env [ 'omniauth.error' ] type = env [ 'omniauth.error.type' ] strategy = env [ 'omniauth.error.strategy' ] logger . debug2 "error = #{error} (#{error.class})" logger . debug2 "error.methods = #{error.methods.sort.join(', ')}" logger . debug2 "error.message = #{error.message} (#{error.message.class})" request_uri = env [ 'REQUEST_URI' ] uri_prefix = "#{SITE_URL}auth/facebook/callback?error" if request_uri . first ( uri_prefix . length ) == uri_prefix and type == :invalid_credentials and error . class == OmniAuth :: Strategies :: OAuth2 :: CallbackError and params [ :error ] == 'access_denied' logger . debug2 "facebook login was cancelled" save_flash_key ".login_cancelled" , :provider => 'facebook' , :appname => APP_NAME redirect_to :controller => :auth return end type = env [ 'omniauth.error.type' ] if request_uri == "#{SITE_URL}auth/linkedin/callback" and type == :invalid_credentials and error . class == OAuth :: Problem and error . message == 'parameter_absent' client = get_linkedin_api_client ( ) if client logger . debug2 "request for linked rw_nus priv. was cancelled" save_flash_key ".linkedin_rw_nus_cancelled" , :appname => APP_NAME redirect_to :controller => :gifts else logger . debug2 "linkedin login was cancelled" save_flash_key ".login_cancelled" , :provider => 'linkedin' , :appname => APP_NAME redirect_to :controller => :auth end return end logger . debug2 "request_uri = #{request_uri}" logger . debug2 "type = #{type} (#{type.class})" logger . debug2 "error.class = #{error.class}" logger . debug2 "error.message = #{error.message}" uri_prefix = "#{SITE_URL}auth/twitter/callback?denied=" if request_uri . first ( uri_prefix . length ) == uri_prefix and type == :invalid_credentials and error . class == OAuth :: Unauthorized and error . message == '401 Unauthorized' logger . debug2 "twitter login was cancelled" save_flash_key ".login_cancelled" , :provider => 'twitter' , :appname => APP_NAME redirect_to :controller => :auth return end message = $1 if error . message =~ / "message": "(.*?)" / message = error . message unless message message = message . to_s . first ( 40 ) save_flash_key '.authentication_failure' , :provider => provider_downcase ( strategy . name ) , :type => type , :message => message redirect_to '/auth' end
omniauth callback on failure (login was started from rails)
oauth_failure is also used if user cancels authorization/login
omniauth callback on failure ( login was started from rails ) oauth_failure is also used if user cancels authorization / login
# logger.debug2  "env.keys = #{env.keys.sort.join(', ')}" # logger.debug2  "env = #{env} (#{env.class})" # check cancelled facebook login # Parameters: {"error_reason"=>"user_denied", #              "error"=>"access_denied", #              "error_description"=>"The user denied your request.", "state"=>"480ee4d402ad5b940d6b48 # error.message = OmniAuth::Strategies::OAuth2::CallbackError (String) # request_uri = http://localhost/auth/facebook/callback?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.&state=480ee4d402ad5b940d6b48805c6ec91ac70f840d400ac998 # type = invalid_credentials (Symbol) # error.class = OmniAuth::Strategies::OAuth2::CallbackError # error.message = OmniAuth::Strategies::OAuth2::CallbackError # todo: check cancelled google+ login # no cancel button in google+ - use have to use back button # check for cancelled linkedin login # that is first logon with scope r_basicprofile r_network # and additional authorisation with scope r_basicprofile r_network rw_nus.) # todo: check cancelled twitter login # twitter login fejlede! invalid_credentials: 401 Unauthorized # request_uri = http://localhost/auth/twitter/callback?denied=2ddtp3zYx5CdldwXCOshMuFVC3QEiAMyAJpKUbO4Fc # type = invalid_credentials (Symbol) # error.class = OAuth::Unauthorized # error.message = 401 Unauthorized # Parameters: {"denied"=>"2ddtp3zYx5CdldwXCOshMuFVC3QEiAMyAJpKUbO4Fc"} # logger.debug2  "type = #{type}" # logger.debug2  "strategy = #{strategy}" # logger.debug2  "strategy.methods = #{strategy.methods.sort.join(', ')}" # logger.debug2  "strategy.name = #{strategy.name}" #error = : #    { #        "errorCode": 0, #    "message": "Unable to verify access token", #    "requestId": "K7SXSRYQUA", #    "status": 401, #    "timestamp": 1384762283211 #} #type = invalid_credentials #strategy = #<OmniAuth::Strategies::LinkedIn:0xb6480cb8> #strategy.name = linkedin # flash[:notice] = "Authentication failure! #{type}: #{message}"