2
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ã404_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ ”    ‹      �’QOÛ0Çßù7?ðFTö2#Hª­Ri«4M®íÆIÙ7:öéç4�`hbO>Û¿ûûþçãÊeQ}[MáKu3‡ÕÝõ|V ;Aü:)Ëª/Î³Ó3Äé‚³Dý'ÄÝn—í&™5Vk´Ô6ç)8E™&ÍÄÎÄpk¤N+prÔ1ë´ù	~èPtÚ$ej{TRYƒ2FCc¼z¢ÇIvŠwŸ9ŽÙI‚|ãõÓðÎÙk¦Ô}ar³—Â 8Yx”�«»œ‘ï™à®­!•3tÊw7�ì²ÚmÈ†rö}V,ï‡d‡lÁ%Ø`¶9»,òÅÅ2/™XÈÖp”¯37‰¹bb.#AëµÛ:£ß„oGøÖýz[°™ÒD\OÎwÏ(&‹/­*ßÄ^&¯“^R#¢ÿÕ©þjÆêj=]Tål=¶DÏÕ½ã‡˜XÉ`:‚Ò£È‡§ƒ‹Qò¸ÛÄþâÏ5W[bà^%ßcƒÁq?jÇ‘þ¶Yó÷5       ˆÀ¿Ä605¾ÃÂ ]    ‹      ÕV]oÚ0}ï¯ðü°·ä`­FC¦Ž �¢LÓ4M•b5‰#Û�Ò_?e¬­†ºñ’{“œØçCvì¿	‡�É·Q}š\÷ÑèËÇ~¯ƒ°ðµÑ'¡}Ñtk@w€N´.Z ‹ÅÂ]4\!g0C¢³´	JKk—jŠƒ3¿zœ!?a„šŠ|ÍuÊ‚^NÙ=S¢ÔŠSfF.Ê(åñæP‘)P,§Sž2—²L¸‰rc!
3±r”J7h3íRes3s.uIRÐ	“™©æ£”ç³[ûþÜKÂÐ‚5/?tYÑõþ55Ã`e‰V«V¾NÐœ¤|–·±|žÍ�’q�E® JI~çÎø#’ê6þÞëœ™¨ú:ð	J$›¶ñ‡N{p9l‡8�Œù@öc®æ
}¢4ÊåSÎèAð�ßð‡Ã†2K^h.òG(‰»Rc‘ª‚­ïŒ‚Dî¢,„>å‰1ct5î&aol-¡Õ�ì^%hŒˆd¹F!—,ÖB.×ú-™·y¤ŠËÍ-Z«“|–h ä ½ÈXRæw¹Xä»®Ç÷ú—òVi¢¶í.ÙßØÕkõsÇ«;µ&òÞ·j šýãóßÊ˜Š”2¹«âPª6ãûºyR�ç4jÈ»h5+xå 2r¿	bÛž^…X0ir°õü�ÃóùW¶+ÃßÖä_FfcÒ,«4lû\zY˜•P]ÿ—Eðò%››Ý¶Ãý?xæïÖV' ì�í'¡Ü{
       	ˆÀ¿Ä‚h ¾ÃÂ š    	‹      ¥’QOÛ0Çßù‡x#W({ÇK*­Ri«’iBÓ\Û�-’8²otåÓ“4E0	4!ž|¶þßýÏÇ�óEVÜ-'ð½¸™ÁòÇ·Ù4vŠøsœ!æE>\\$£3ÄÉœ³Dí%âv»M¶ãÄ‡‹Zª«Œœ¢D“fâˆ÷gâ¸5Rw+prT1m´ù~èÿPtÚŒÎñQÖµÔHu‹J*kPÆh(blƒW÷}ô0NF(w‘Nº|íõ®OwöYéNa_¦\ï3ôaœ,<ÈÊ•MÊÈ·LpW—ƒJ:å›ˆëJ6÷Ié6dE)û5Í¿;Éö¯—`ƒÙ¤ìk–Î¯iÎÄ\Ö†£|›¹é˜k&f2Ô^»�3ú]øv€oÝãû‚ùÀä&ªàZr¾yA±³øÚªòUleçõKçÀ†×Ô€èÿuCªš±¼^MæE>]-Ñ½ÄKuÿ(&–2˜† wÁ(òaw03(Ÿ4ëØ^=oáPjp¥%& NáMò#]ÀÃ|pÜÇaÎŸ *6¯J    $   H403239_•I|¥‰ÓMjqØ‚¦ ë<óo¬ÅÄ  ï    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
</body></html>
  D   ˆl–Ãa¾”*i?u8 …p/Üiå1hß�þFã‹8à,Œ¼Ø€Ë¿ÏÈƒŽÇ_�uÐb&=LyZËcõÇÆ 
f    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

module Gql::Mutations::Concerns::HandlesAuthentication
  extend ActiveSupport::Concern

  included do # rubocop:disable Metrics/BlockLength

    # reimplementation of `authenticate_with_password`
    def authenticate(login:, password:, two_factor_authentication: nil, two_factor_recovery: nil, remember_me: false)
      auth = begin
        if two_factor_authentication.present?
          Auth.new(login, password, **two_factor_authentication)
        elsif two_factor_recovery.present?
          Auth.new(login, password, two_factor_method: 'recovery_codes', two_factor_payload: two_factor_recovery[:recovery_code])
        else
          Auth.new(login, password)
        end
      end

      begin
        auth.valid!
      rescue Auth::Error::TwoFactorRequired => e
        return {
          two_factor_required: {
            default_two_factor_authentication_method:    e.default_two_factor_authentication_method,
            available_two_factor_authentication_methods: e.available_two_factor_authentication_methods,
            recovery_codes_available:                    e.recovery_codes_available
          }
        }
      rescue Auth::Error::Base => e
        return error_response({ message: e.message })
      end

      create_session(auth&.user, remember_me)

      authenticate_result
    end

    def authenticate_result
      {
        session: {
          session_id: context[:controller].session.id,
          after_auth: Auth::AfterAuth.run(context.current_user, context[:controller].session, options: { initial: true })
        }
      }
    end

    def create_session(user, remember_me, authentication_type = 'password')
      context[:controller].session.delete(:switched_from_user_id)

      # authentication_check_prerequesits is private
      context[:controller].send(:authentication_check_prerequesits, user, 'session')
      context[:current_user] = user

      initiate_session_for(user, remember_me, authentication_type)
    end

    def initiate_session_for(user, remember_me, authentication_type)
      # TODO: Check if this can be moved to a central pla