Module: Github::Authorization

Included in:
API
Defined in:
lib/github_api/authorization.rb

Instance Method Summary collapse

Instance Method Details

#auth_codeObject

Strategy token


19
20
21
22
# File 'lib/github_api/authorization.rb', line 19

def auth_code
  _verify_client
  client.auth_code
end

#authenticated?Boolean

Check whether authentication credentials are present

Returns:

  • (Boolean)

47
48
49
# File 'lib/github_api/authorization.rb', line 47

def authenticated?
  basic_authed? || oauth_token?
end

#authenticationObject

Select authentication parameters


59
60
61
62
63
64
65
# File 'lib/github_api/authorization.rb', line 59

def authentication
  if basic_authed?
    { login: , password: password }
  else
    {}
  end
end

#authorize_url(params = {}) ⇒ Object

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.


35
36
37
38
# File 'lib/github_api/authorization.rb', line 35

def authorize_url(params = {})
  _verify_client
  client.auth_code.authorize_url(params)
end

#basic_authed?Boolean

Check whether basic authentication credentials are present

Returns:

  • (Boolean)

52
53
54
# File 'lib/github_api/authorization.rb', line 52

def basic_authed?
  basic_auth? || (login? && password?)
end

#clientObject

Setup OAuth2 instance


7
8
9
10
11
12
13
14
15
16
# File 'lib/github_api/authorization.rb', line 7

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 = {}) ⇒ Object

Makes request to token endpoint and retrieves access token value


41
42
43
44
# File 'lib/github_api/authorization.rb', line 41

def get_token(authorization_code, params = {})
  _verify_client
  client.auth_code.get_token(authorization_code, params)
end