Module: Github::Authorization

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

Instance Method Summary collapse

Instance Method Details

#auth_codeObject

Strategy token



21
22
23
24
# File 'lib/github_api2/authorization.rb', line 21

def auth_code
  _verify_client
  client.auth_code
end

#authenticated?Boolean

Check whether authentication credentials are present

Returns:

  • (Boolean)


49
50
51
# File 'lib/github_api2/authorization.rb', line 49

def authenticated?
  basic_authed? || oauth_token?
end

#authenticationObject

Select authentication parameters



61
62
63
64
65
66
67
# File 'lib/github_api2/authorization.rb', line 61

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.



37
38
39
40
# File 'lib/github_api2/authorization.rb', line 37

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)


54
55
56
# File 'lib/github_api2/authorization.rb', line 54

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

#clientObject

Setup OAuth2 instance



9
10
11
12
13
14
15
16
17
18
# File 'lib/github_api2/authorization.rb', line 9

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



43
44
45
46
# File 'lib/github_api2/authorization.rb', line 43

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