module Github::Authorization

Attributes

scopes[RW]

Public Instance Methods

auth_code() click to toggle source

Strategy token

# File lib/github_api/authorization.rb, line 20
def auth_code
  _verify_client
  client.auth_code
end
authenticated?() click to toggle source

Check whether authentication credentials are present

# File lib/github_api/authorization.rb, line 48
def authenticated?
  basic_authed? || oauth_token?
end
authentication() click to toggle source

Select authentication parameters

# File lib/github_api/authorization.rb, line 58
def authentication
  if basic_auth?
    { :basic_auth => basic_auth }
  elsif login? && password?
    { :login => login, :password => password }
  else
    { }
  end
end
authorize_url(params = {}) click to toggle source

Sends authorization request to GitHub.

Parameters

  • :redirect_uri - Optional string.

  • :scope - Optional string. Comma separated list of scopes. Available scopes:

    • (no scope) - public read-only access (includes public user profile info, public repo info, and gists).

    • user - DB read/write access to profile info only.

    • public_repo - DB read/write access, and Git read access to public repos.

    • repo - DB read/write access, and Git read access to public and private repos.

    • gist - write access to gists.

# File lib/github_api/authorization.rb, line 36
def authorize_url(params = {})
  _verify_client
  client.auth_code.authorize_url(params)
end
basic_authed?() click to toggle source

Check whether basic authentication credentials are present

# File lib/github_api/authorization.rb, line 53
def basic_authed?
  basic_auth? || (login? && password?)
end
client() click to toggle source

Setup OAuth2 instance

# File lib/github_api/authorization.rb, line 8
def client
  @client ||= ::OAuth2::Client.new(client_id, client_secret,
    {
      :site          => current_options.fetch(:site) { Github.site },
      :authorize_url => 'login/oauth/authorize',
      :token_url     => 'login/oauth/access_token',
      :ssl           => { :verify => false }
    }
  )
end
get_token(authorization_code, params = {}) click to toggle source

Makes request to token endpoint and retrieves access token value

# File lib/github_api/authorization.rb, line 42
def get_token(authorization_code, params = {})
  _verify_client
  client.auth_code.get_token(authorization_code, params)
end