Sha256: ea890a47d0f9e4679db28cd8d659e53e38ce5a449d38cb6c749cf186ef89919d

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module Vidibus
  module User
    module Warden
      module Helper

        # Sets credentials for Connector login in session.
        # The client_secret will be validated through Vidibus' OauthServer
        # when issuing an OAuth token. To protect the service's secret, a
        # custom signature will be sent instead.
        def credentials
          @credentials ||= begin
            service = ::Service.discover(:user, realm)
            unless service
              raise(ServiceError, 'No user service is available.')
            end
            {
              :client_id => "#{this.uuid}-#{realm}",
              :client_secret => Vidibus::Secure.sign(this.uuid, service.secret),
              :service_url => service.url
            }
          end
        end

        # Returns this service
        def this
          @this ||= ::Service.this
        end

        # Returns the current realm
        def realm
          @realm ||= params['realm'] || env[:realm]
        end

        # Returns OAuth client
        def client
          @client ||= OAuth2::Client.new(credentials[:client_id], credentials[:client_secret], :site => credentials[:service_url])
        end

        # Returns current host.
        def host
          "#{protocol}#{env['HTTP_HOST']}"
        end

        # Returns protocol depending on SERVER_PORT.
        def protocol
          env['SERVER_PORT'] == 443 ? 'https://' : 'http://'
        end

        def logger
          Vidibus::User.logger
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vidibus-user-1.0.0 lib/vidibus/user/warden/helper.rb