Class: Neetob::CLI::Github::Auth
- Inherits:
-
Object
- Object
- Neetob::CLI::Github::Auth
- Defined in:
- lib/neetob/cli/github/auth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#grant_type ⇒ Object
Returns the value of attribute grant_type.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#ui ⇒ Object
Returns the value of attribute ui.
-
#uris ⇒ Object
Returns the value of attribute uris.
Instance Method Summary collapse
-
#initialize(client_id:, grant_type:, auth_uris:, provider:, scope:) ⇒ Auth
constructor
A new instance of Auth.
- #open_url_in_browser!(url) ⇒ Object
- #request_authorization ⇒ Object
- #start_oauth2_device_flow ⇒ Object
- #token_persisted? ⇒ Boolean
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_token ⇒ Object
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_id ⇒ Object
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_type ⇒ Object
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 |
#provider ⇒ Object
Returns the value of attribute provider.
14 15 16 |
# File 'lib/neetob/cli/github/auth.rb', line 14 def provider @provider end |
#scope ⇒ Object
Returns the value of attribute scope.
14 15 16 |
# File 'lib/neetob/cli/github/auth.rb', line 14 def scope @scope end |
#ui ⇒ Object
Returns the value of attribute ui.
14 15 16 |
# File 'lib/neetob/cli/github/auth.rb', line 14 def ui @ui end |
#uris ⇒ Object
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_authorization ⇒ Object
43 44 45 |
# File 'lib/neetob/cli/github/auth.rb', line 43 def post(uris["auth_req"], params: { client_id:, scope: }) end |
#start_oauth2_device_flow ⇒ Object
36 37 38 39 40 41 |
# File 'lib/neetob/cli/github/auth.rb', line 36 def start_oauth2_device_flow auth_data = show_user_code(auth_data[:user_code]) open_url_in_browser!(auth_data[:verification_uri]) poll_for_token(auth_data) end |
#token_persisted? ⇒ Boolean
26 27 28 |
# File 'lib/neetob/cli/github/auth.rb', line 26 def token_persisted? access_token_present? end |