Sha256: 5256ec9b374766ddd2e3b1db13e643c0a2617008fc791d7449011e191c1ad76d

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module Softwear
  module Auth
    class Controller < ::ApplicationController
      skip_before_filter :authenticate_user!, only: [:set_session_token, :clear_query_cache]

      def self.abstract_class?
        true
      end

      # ====================
      # Comes from an img tag on softwear-hub to let an authorized app know that
      # a user has signed in.
      # ====================
      def set_session_token
        encrypted_token = params[:token]
        redirect_to Figaro.env.softwear_hub_url and return if encrypted_token.blank?

        Rails.logger.info "RECEIVED ENCRYPTED TOKEN: #{encrypted_token}"

        decipher = OpenSSL::Cipher::AES.new(256, :CBC)
        decipher.decrypt
        decipher.key = Figaro.env.token_cipher_key.first(32)
        decipher.iv  = Figaro.env.token_cipher_iv.first(16)

        session[:user_token] = decipher.update(Base64.urlsafe_decode64(encrypted_token)) + decipher.final

        render inline: 'Done'
      end

      # ====================
      # Comes from an img tag on softwear-hub when there has been a change to user
      # attributes or roles and the cache should be cleared.
      # ====================
      def clear_query_cache
        Softwear::Auth::Model.descendants.each do |user|
          user.query_cache.clear
        end

        render inline: 'Done'
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
softwear-lib-3.3.7 lib/softwear/auth/controller.rb
softwear-lib-3.3.6 lib/softwear/auth/controller.rb
softwear-lib-3.3.5 lib/softwear/auth/controller.rb
softwear-lib-3.1.5 lib/softwear/auth/controller.rb
softwear-lib-3.1.4 lib/softwear/auth/controller.rb
softwear-lib-3.1.3 lib/softwear/auth/controller.rb