Sha256: db8a49ef7a00e84df8d0aa55f73434d95d7e692880f077fbaf41a50f15e69be1

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module Sso
  module Doorkeeper
    module AuthorizationsControllerMixin
      extend ActiveSupport::Concern
      include ::Sso::Logging

      included do
        after_action :after_grant_create, only: [:new, :create]
      end

    protected

      def after_grant_create
        debug { "AuthorizationsController#Create : after_action" }
        code_response = authorization.instance_variable_get("@response")
        oauth_grant = code_response.try(:auth).try(:token)

        warden_session = session["warden.user.user.session"]
        sso_session = Sso::Session.find(warden_session["sso_session_id"].to_s)

        if !sso_session.try(:active?)
          error { "ERROR : AuthorizationsControllerMixin  - Sso::Session INACTIVE) #{sso_session.inspect}"}
          warden.logout(:user) and return
        end

        if oauth_grant
          debug { "Sso::Session.update_master_with_grant - #{sso_session.id.inspect}, #{oauth_grant.inspect}" }
          sso_session.clients.find_or_create_by!(access_grant_id: oauth_grant.id)
        else
          error { "ERROR : AuthorizationsControllerMixin - Unable to get grant id from #{oauth_grant.inspect}"}
          warden.logout(:user) and return
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper_sso-0.2.3 lib/sso/doorkeeper/authorizations_controller_mixin.rb
doorkeeper_sso-0.2.2 lib/sso/doorkeeper/authorizations_controller_mixin.rb