Class: Legion::Extensions::Github::Helpers::BrowserAuth
- Inherits:
-
Object
- Object
- Legion::Extensions::Github::Helpers::BrowserAuth
- Defined in:
- lib/legion/extensions/github/helpers/browser_auth.rb
Constant Summary collapse
- DEFAULT_SCOPES =
'repo admin:org admin:repo_hook read:user'
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #gui_available? ⇒ Boolean
-
#initialize(client_id:, client_secret: nil, scopes: DEFAULT_SCOPES, auth: nil) ⇒ BrowserAuth
constructor
A new instance of BrowserAuth.
- #open_browser(url) ⇒ Object
Constructor Details
#initialize(client_id:, client_secret: nil, scopes: DEFAULT_SCOPES, auth: nil) ⇒ BrowserAuth
Returns a new instance of BrowserAuth.
17 18 19 20 21 22 |
# File 'lib/legion/extensions/github/helpers/browser_auth.rb', line 17 def initialize(client_id:, client_secret: nil, scopes: DEFAULT_SCOPES, auth: nil, **) @client_id = client_id @client_secret = client_secret @scopes = scopes @auth = auth || Object.new.extend(OAuth::Runners::Auth) end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
15 16 17 |
# File 'lib/legion/extensions/github/helpers/browser_auth.rb', line 15 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
15 16 17 |
# File 'lib/legion/extensions/github/helpers/browser_auth.rb', line 15 def client_secret @client_secret end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
15 16 17 |
# File 'lib/legion/extensions/github/helpers/browser_auth.rb', line 15 def scopes @scopes end |
Instance Method Details
#authenticate ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/github/helpers/browser_auth.rb', line 24 def authenticate if gui_available? authenticate_browser else authenticate_device_code end end |
#gui_available? ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/legion/extensions/github/helpers/browser_auth.rb', line 32 def gui_available? os = host_os return true if /darwin|mswin|mingw/.match?(os) !ENV['DISPLAY'].nil? || !ENV['WAYLAND_DISPLAY'].nil? end |
#open_browser(url) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/github/helpers/browser_auth.rb', line 39 def open_browser(url) cmd = case host_os when /darwin/ then 'open' when /linux/ then 'xdg-open' when /mswin|mingw/ then 'start' end return false unless cmd system(cmd, url) end |