module Octokit::Authentication

Authentication methods for {Octokit::Client}

Public Instance Methods

application_authenticated?() click to toggle source

Indicates if the client has OAuth Application client_id and secret credentials to make anonymous requests at a higher rate limit

@see developer.github.com/v3/#unauthenticated-rate-limited-requests @return Boolean

# File lib/octokit/authentication.rb, line 39
def application_authenticated?
  !!application_authentication
end
basic_authenticated?() click to toggle source

Indicates if the client was supplied Basic Auth username and password

@see developer.github.com/v3/#authentication @return [Boolean]

# File lib/octokit/authentication.rb, line 11
def basic_authenticated?
  !!(@login && @password)
end
token_authenticated?() click to toggle source

Indicates if the client was supplied an OAuth access token

@see developer.github.com/v3/#authentication @return [Boolean]

# File lib/octokit/authentication.rb, line 20
def token_authenticated?
  !!@access_token
end
user_authenticated?() click to toggle source

Indicates if the client was supplied an OAuth access token or Basic Auth username and password

@see developer.github.com/v3/#authentication @return [Boolean]

# File lib/octokit/authentication.rb, line 29
def user_authenticated?
  basic_authenticated? || token_authenticated?
end

Private Instance Methods

application_authentication() click to toggle source
# File lib/octokit/authentication.rb, line 45
def application_authentication
  if @client_id && @client_secret
    {
      :client_id     => @client_id,
      :client_secret => @client_secret
    }
  end
end
login_from_netrc() click to toggle source
# File lib/octokit/authentication.rb, line 54
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