Class: Itch::Auth
Overview
Authentication flow handler
Instance Attribute Summary collapse
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#totp ⇒ Object
writeonly
Sets the attribute totp.
-
#username ⇒ Object
writeonly
Sets the attribute username.
Instance Method Summary collapse
-
#initialize(agent, username: nil, password: nil, cookie_path: nil) ⇒ Auth
constructor
A new instance of Auth.
- #logged_in? ⇒ Boolean
- #login ⇒ Object
- #page_is_2fa?(page) ⇒ Boolean
- #page_is_login?(page) ⇒ Boolean
Methods included from SimpleInspect
#inspect, #pretty_print_instance_variables
Constructor Details
#initialize(agent, username: nil, password: nil, cookie_path: nil) ⇒ Auth
Returns a new instance of Auth.
12 13 14 15 16 17 18 |
# File 'lib/itch/auth.rb', line 12 def initialize(agent, username: nil, password: nil, cookie_path: nil) @agent = agent @cookie_path = @username = username @password = password @totp = -> {} end |
Instance Attribute Details
#password=(value) ⇒ Object
Sets the attribute password
10 11 12 |
# File 'lib/itch/auth.rb', line 10 def password=(value) @password = value end |
#totp=(value) ⇒ Object (writeonly)
Sets the attribute totp
10 11 12 |
# File 'lib/itch/auth.rb', line 10 def totp=(value) @totp = value end |
#username=(value) ⇒ Object
Sets the attribute username
10 11 12 |
# File 'lib/itch/auth.rb', line 10 def username=(value) @username = value end |
Instance Method Details
#logged_in? ⇒ Boolean
20 21 22 |
# File 'lib/itch/auth.rb', line 20 def logged_in? @agent.get(Itch::URL::DASHBOARD).uri.to_s == Itch::URL::DASHBOARD end |
#login ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/itch/auth.rb', line 24 def login page = @agent.get(Itch::URL::LOGIN) return unless page.code == "200" raise AuthError, "Email and password are required for login" if @username.nil? || @password.nil? page = submit_login(page) if page_is_login?(page) submit_2fa(page) if page_is_2fa?(page) logged_in? end |
#page_is_2fa?(page) ⇒ Boolean
41 42 43 |
# File 'lib/itch/auth.rb', line 41 def page_is_2fa?(page) page.uri.to_s.start_with?(Itch::URL::TOTP_FRAGMENT) end |