Class: Neetob::CLI::Github::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/neetob/cli/github/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, grant_type:, auth_uris:, provider:, scope:) ⇒ Auth

Returns a new instance of Auth.



16
17
18
19
20
21
22
23
24
# File 'lib/neetob/cli/github/auth.rb', line 16

def initialize(client_id:, grant_type:, auth_uris:, provider:, scope:)
  @client_id = client_id
  @grant_type = grant_type
  @uris = auth_uris
  @provider = provider
  @scope = scope
  @access_token = retrieve_persisted_token
  @ui = CLI::UI.new
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



14
15
16
# File 'lib/neetob/cli/github/auth.rb', line 14

def access_token
  @access_token
end

#client_idObject

Returns the value of attribute client_id.



14
15
16
# File 'lib/neetob/cli/github/auth.rb', line 14

def client_id
  @client_id
end

#grant_typeObject

Returns the value of attribute grant_type.



14
15
16
# File 'lib/neetob/cli/github/auth.rb', line 14

def grant_type
  @grant_type
end

#providerObject

Returns the value of attribute provider.



14
15
16
# File 'lib/neetob/cli/github/auth.rb', line 14

def provider
  @provider
end

#scopeObject

Returns the value of attribute scope.



14
15
16
# File 'lib/neetob/cli/github/auth.rb', line 14

def scope
  @scope
end

#uiObject

Returns the value of attribute ui.



14
15
16
# File 'lib/neetob/cli/github/auth.rb', line 14

def ui
  @ui
end

#urisObject

Returns the value of attribute uris.



14
15
16
# File 'lib/neetob/cli/github/auth.rb', line 14

def uris
  @uris
end

Instance Method Details

#open_url_in_browser!(url) ⇒ Object



30
31
32
33
34
# File 'lib/neetob/cli/github/auth.rb', line 30

def open_url_in_browser!(url)
  Launchy.open(url) do |exception|
    raise(StandardError, "Attempted to open #{url} in browser and failed because #{exception}.")
  end
end

#request_authorizationObject



43
44
45
# File 'lib/neetob/cli/github/auth.rb', line 43

def request_authorization
  post(uris["auth_req"], params: { client_id:, scope: })
end

#start_oauth2_device_flowObject



36
37
38
39
40
41
# File 'lib/neetob/cli/github/auth.rb', line 36

def start_oauth2_device_flow
  auth_data = request_authorization
  show_user_code(auth_data[:user_code])
  open_url_in_browser!(auth_data[:verification_uri])
  poll_for_token(auth_data)
end

#token_persisted?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/neetob/cli/github/auth.rb', line 26

def token_persisted?
  access_token_present?
end