app/controllers/auth_controller.rb
# omniauth callback on success (login was started from rails)
omniauth callback on success (login was started from rails)
omniauth callback on success ( login was started from rails )
def create
    logger.debug2 "get_session_value(:did) = #{get_session_value(:did)}"
    @auth_hash = auth_hash
    client_userid = get_client_userid()
    logger.secret2 "auth_hash = #{auth_hash}"
    angular_url = "/#{I18n.locale}/main#/"
    provider = auth_hash.get_provider
    if env['action_dispatch.request.unsigned_session_cookie']
      omniauth_status = env['action_dispatch.request.unsigned_session_cookie']['omniauth.state']
    end
    logger.debug2 "omniauth_status = #{omniauth_status}"
    logger.debug2 "params[:state] = #{params[:state]}"
    if (params.has_key?(:state) or omniauth_status) and params[:state] != omniauth_status
      logger.debug2 "invalid state after omniauth login. omniauth_status = #{omniauth_status}, params[:state] = #{params[:state]}"
      save_flash_key ".invalid_state_login", :apiname => provider_downcase(provider)
      redirect_to "#{angular_url}auth/#{client_userid}"
      return
    end
    res = login :provider => provider,
                :token => auth_hash.get_token,
                :expires_at => auth_hash.get_expires_at,
                :refresh_token => auth_hash.get_refresh_token,
                :uid => auth_hash.get_uid,
                :name => auth_hash.get_user_name,
                :image => auth_hash.get_image,
                :country => auth_hash.get_country,
                :language => auth_hash.get_language,
                :profile_url => auth_hash.get_profile_url
    if !res
      user_id = login_user_ids.find { |userid2| userid2.split('/').last == provider }
      user = User.find_by_user_id(user_id)
      if @users.size == 1
        redirect_to "#{angular_url}gifts/#{client_userid}"
      else
        redirect_to "#{angular_url}auth/#{client_userid}"
      end
    else
      key, options = res
      begin
        save_flash_key key, options
      rescue => e
        logger.debug2  "invalid response from User.find_or_create_from_auth_hash. Must be nil or a valid input to translate. Response: #{user}"
        save_flash_key '.find_or_create_from_auth_hash', :response => user, :exception => e.message.to_s
      end
      redirect_to "#{angular_url}auth/#{client_userid}"
    end
  end
def create logger . debug2 "get_session_value(:did) = #{get_session_value(:did)}" @auth_hash = auth_hash client_userid = get_client_userid ( ) logger . secret2 "auth_hash = #{auth_hash}" angular_url = "/#{I18n.locale}/main#/" provider = auth_hash . get_provider if env [ 'action_dispatch.request.unsigned_session_cookie' ] omniauth_status = env [ 'action_dispatch.request.unsigned_session_cookie' ] [ 'omniauth.state' ] end logger . debug2 "omniauth_status = #{omniauth_status}" logger . debug2 "params[:state] = #{params[:state]}" if ( params . has_key? ( :state ) or omniauth_status ) and params [ :state ] != omniauth_status logger . debug2 "invalid state after omniauth login. omniauth_status = #{omniauth_status}, params[:state] = #{params[:state]}" save_flash_key ".invalid_state_login" , :apiname => provider_downcase ( provider ) redirect_to "#{angular_url}auth/#{client_userid}" return end res = login :provider => provider , :token => auth_hash . get_token , :expires_at => auth_hash . get_expires_at , :refresh_token => auth_hash . get_refresh_token , :uid => auth_hash . get_uid , :name => auth_hash . get_user_name , :image => auth_hash . get_image , :country => auth_hash . get_country , :language => auth_hash . get_language , :profile_url => auth_hash . get_profile_url if ! res user_id = login_user_ids . find { | userid2 | userid2 . split ( '/' ) . last == provider } user = User . find_by_user_id ( user_id ) if @users . size == 1 redirect_to "#{angular_url}gifts/#{client_userid}" else redirect_to "#{angular_url}auth/#{client_userid}" end else key , options = res begin save_flash_key key , options rescue => e logger . debug2 "invalid response from User.find_or_create_from_auth_hash. Must be nil or a valid input to translate. Response: #{user}" save_flash_key '.find_or_create_from_auth_hash' , :response => user , :exception => e . message . to_s end redirect_to "#{angular_url}auth/#{client_userid}" end end
omniauth callback on success (login was started from rails)
omniauth callback on success ( login was started from rails )
# todo: debug problems with missing did after login # angularJS single page url: main#/auth/:client_userid or main#/gifts/:client_userid # check state - only relevant for auth 2.0 - maybe already done in omniauth-oauth2? # logger.secret2 "env['action_dispatch.request.unsigned_session_cookie'] = #{env['action_dispatch.request.unsigned_session_cookie']}" # use key auth.create.invalid_state_login in case of invalid state # oauth2 and invalid state # login - return nil (ok) or array with translate key and options for error message # auth_hash.get_xxx methods are defined in initializers/omniauth*.rb # auth hash debugging for new login providers: # if provider == 'facebook' and auth_hash.get_uid.to_s == '99999999' # logger.debug2 'checking structure of auth hash for facebook' # t = Task.new # t.session_id = session[:session_id] # t.task = 'facebook' # t.priority = 5 # t.ajax = 'N' # t.task_data = auth_hash.to_yaml # t.save! # end # login ok - flash message has been set in login method # singleton user login - continue to gifts page # multi user login - stay on login page for other logins, check expired access tokens, share share level, find friends etc # login failed # todo: copy translate error handling from util.do_tasks