Class: Pickpoint::Auth::ClientAuthSession
- Inherits:
-
Object
- Object
- Pickpoint::Auth::ClientAuthSession
- Defined in:
- lib/pickpoint/auth.rb
Instance Method Summary collapse
-
#initialize(initial, base_url, http) ⇒ ClientAuthSession
constructor
A new instance of ClientAuthSession.
- #refresh ⇒ Object
- #refresh_after_unauthorized ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(initial, base_url, http) ⇒ ClientAuthSession
Returns a new instance of ClientAuthSession.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/pickpoint/auth.rb', line 77 def initialize(initial, base_url, http) if blank?(initial.access_token) || blank?(initial.refresh_token) || initial.expires_at.to_i.zero? raise InvalidConfigError, "client_auth requires access_token, refresh_token, and expires_at (unix ms)" end @mutex = Monitor.new @cond = @mutex.new_cond @access = initial.access_token @refresh = initial.refresh_token @expires_at = initial.expires_at.to_i @issued_at = Time.now @base_url = base_url @http = http @refreshing = false @waiters = 0 @last_refresh_error = nil end |
Instance Method Details
#refresh ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pickpoint/auth.rb', line 107 def refresh wait = false refresh_tok = nil @mutex.synchronize do if @refreshing @waiters += 1 wait = true else @refreshing = true @last_refresh_error = nil refresh_tok = @refresh end end if wait @mutex.synchronize do @cond.wait_while { @refreshing } err = @last_refresh_error @waiters -= 1 raise err if err end return end err = nil begin do_refresh(refresh_tok) rescue StandardError => e err = e end @mutex.synchronize do @last_refresh_error = err @refreshing = false @cond.broadcast end raise err if err end |
#refresh_after_unauthorized ⇒ Object
100 101 102 103 104 105 |
# File 'lib/pickpoint/auth.rb', line 100 def refresh true rescue StandardError false end |
#token ⇒ Object
95 96 97 98 |
# File 'lib/pickpoint/auth.rb', line 95 def token refresh if needs_proactive_refresh? @mutex.synchronize { @access } end |