Sha256: 073755c3a47c9791d72e1c44927f183bcbcac9d6a37dc796e74b1fd6963e1554

Contents?: true

Size: 1.92 KB

Versions: 24

Compression:

Stored size: 1.92 KB

Contents

module Octokit

  # Authentication methods for {Octokit::Client}
  module Authentication

    # Indicates if the client was supplied  Basic Auth
    # username and password
    #
    # @see https://developer.github.com/v3/#authentication
    # @return [Boolean]
    def basic_authenticated?
      !!(@login && @password)
    end

    # Indicates if the client was supplied an OAuth
    # access token
    #
    # @see https://developer.github.com/v3/#authentication
    # @return [Boolean]
    def token_authenticated?
      !!@access_token
    end

    # Indicates if the client was supplied an OAuth
    # access token or Basic Auth username and password
    #
    # @see https://developer.github.com/v3/#authentication
    # @return [Boolean]
    def user_authenticated?
      basic_authenticated? || token_authenticated?
    end

    # Indicates if the client has OAuth Application
    # client_id and secret credentials to make anonymous
    # requests at a higher rate limit
    #
    # @see https://developer.github.com/v3/#unauthenticated-rate-limited-requests
    # @return Boolean
    def application_authenticated?
      !!application_authentication
    end

    private

    def application_authentication
      if @client_id && @client_secret
        {
          :client_id     => @client_id,
          :client_secret => @client_secret
        }
      end
    end

    def login_from_netrc
      return unless netrc?

      require 'netrc'
      info = Netrc.read netrc_file
      netrc_host = URI.parse(api_endpoint).host
      creds = info[netrc_host]
      if creds.nil?
        # creds will be nil if there is no netrc for this end point
        octokit_warn "Error loading credentials from netrc file for #{api_endpoint}"
      else
        creds = creds.to_a
        self.login = creds.shift
        self.password = creds.shift
      end
    rescue LoadError
      octokit_warn "Please install netrc gem for .netrc support"
    end

  end
end

Version data entries

24 entries across 23 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/octokit-4.6.2/lib/octokit/authentication.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/octokit-4.6.2/lib/octokit/authentication.rb
tdiary-5.0.4 vendor/bundle/gems/octokit-4.6.2/lib/octokit/authentication.rb
octokit-4.6.2 lib/octokit/authentication.rb
octokit-4.6.1 lib/octokit/authentication.rb
octokit-4.6.0 lib/octokit/authentication.rb
octokit-4.4.1 lib/octokit/authentication.rb
octokit-4.4.0 lib/octokit/authentication.rb
tdiary-5.0.2 vendor/bundle/gems/octokit-4.3.0/lib/octokit/authentication.rb
tdiary-5.0.1 vendor/bundle/gems/octokit-4.3.0/lib/octokit/authentication.rb
octokit-4.3.0 lib/octokit/authentication.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/octokit-4.2.0/lib/octokit/authentication.rb
octokit-4.2.0 lib/octokit/authentication.rb
octokit-4.1.1 lib/octokit/authentication.rb
octokit-4.1.0 lib/octokit/authentication.rb
octokit-4.0.1 lib/octokit/authentication.rb
octokit-4.0.0 lib/octokit/authentication.rb
octokit-3.8.0 lib/octokit/authentication.rb
octokit-3.7.1 lib/octokit/authentication.rb
octokit-3.7.0 lib/octokit/authentication.rb