Sha256: 2a919636a2585a210a743e9146d5b039b9896eafe8fb317a88c4915b439e0462

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

module Devise
  module Oauth2
    module Authorization
      extend ActiveSupport::Concern

      def current_oauth2_client(opts: { secure: false })
        return @secure_client ||= Client.find_by(secret: client_secret) if opts[:secure]
        return @secure_client ||= Client.find_by(id: current_access_token.client_id) if valid_access_token?
        @client ||= Client.find_by('identifier = :client_id OR secret = :secret', client_id: client_id, secret: client_secret) if client_credentials?
      end

      def current_access_token
        @access_token ||= AccessToken.find_by(token: access_token) if accesss_token?
      end

			def valid_access_token?
				!!current_access_token
			end

      def oauth2_client_signed_in?
        !!@client
      end

      def access_token_signed_in?
        !!@access_token
      end

      def client_credentials
        client_id? || client_secret?
      end

      def client_credentials?
        !!client_credentials
      end

      def client_secret
        params[:client_secret]
      end

      def client_secret?
        !!client_secret
      end

      def client_id
        params[:client_id]
      end

      def client_id?
        !!params[:client_id]
      end

      def access_token
        params[:access_token]
      end

      def access_token?
        !!access_token
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise_oauth2_rails4-2.1.3 app/controllers/devise/oauth2/authorization.rb
devise_oauth2_rails4-2.0.3 app/controllers/devise/oauth2/authorization.rb