Sha256: cca83784a98e53ee19a0c02d01781120f5ab2a175373a921d8aab6e491eb6dea

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

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

      # ====================
      # 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
        decipher.iv  = Figaro.env.token_cipher_iv

        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

1 entries across 1 versions & 1 rubygems

Version Path
softwear-lib-1.5.0 lib/softwear/auth/controller.rb