Sha256: 5c49ae3082cc7a3f311514e97aa5582601bb6f7c9a2584fc3bf94bfa20730f95

Contents?: true

Size: 880 Bytes

Versions: 4

Compression:

Stored size: 880 Bytes

Contents

module SocialStream
  module Oauth2Server
    module Controllers
      # Common methods added to ApplicationController
      module Helpers
        extend ActiveSupport::Concern

        def authenticate_user!(opts = {})
          oauth2_token? || super
        end

        def current_subject
          @current_subject ||=
            current_from_oauth_token(:client) || super
        end

        def current_user
          @current_user ||=
            current_from_oauth_token(:user) || super
        end

        def current_from_oauth_token(type)
          return unless oauth2_token?

          oauth2_token.__send__(type)
        end

        def oauth2_token
          @oauth2_token ||=
            request.env[Rack::OAuth2::Server::Resource::ACCESS_TOKEN]
        end

        def oauth2_token?
          oauth2_token.present?
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
social_stream-2.2.2 oauth2_server/lib/social_stream/oauth2_server/controllers/helpers.rb
social_stream-oauth2_server-2.2.2 lib/social_stream/oauth2_server/controllers/helpers.rb
social_stream-2.2.1 oauth2_server/lib/social_stream/oauth2_server/controllers/helpers.rb
social_stream-oauth2_server-2.2.1 lib/social_stream/oauth2_server/controllers/helpers.rb