lib/sp/job/broker.rb in sp-job-0.2.3 vs lib/sp/job/broker.rb in sp-job-0.3.22

- old
+ new

@@ -31,14 +31,14 @@ # # Helper class that defined an 'Broker' error. # - class Error < ::SP::Job::JSONAPIError + class Error < ::SP::Job::JSONAPI::Error def initialize (i18n:, code:, internal:) - super(code: code, internal: internal) + super(status: code, code: code, detail: nil, internal: internal) @i18n = i18n end end @@ -148,11 +148,11 @@ # Refresh an access token. # # @param scope # @param old # - def refresh (scope: nil, old: nil) + def refresh(scope: nil, old: nil, delete: true) at_response = @client.refresh_access_token( a_refresh_token = old[:refresh_token], a_scope = scope ) if true == at_response[:oauth2].has_key?(:error) @@ -166,17 +166,19 @@ # old tokens provided: remove them from redis if nil == @redis || nil == @service_id raise InternalError.new(i18n: nil, internal: nil) end # delete old tokens from redis - @redis.multi do |multi| - if nil != old[:access_token] - multi.del("#{@service_id}:oauth:access_token:#{old[:access_token]}") + if true == delete + @redis.multi do |multi| + if nil != old[:access_token] + multi.del("#{@service_id}:oauth:access_token:#{old[:access_token]}") + end + if nil != old[:refresh_token] + multi.del("#{@service_id}:oauth:refresh_token:#{old[:refresh_token]}") + end end - if nil != old[:refresh_token] - multi.del("#{@service_id}:oauth:refresh_token:#{old[:refresh_token]}") - end end # return oauth response return at_response end @@ -234,14 +236,14 @@ def dispose (access:, refresh:) if nil == @redis || nil == @service_id raise InternalError.new(i18n: nil, internal: nil) end - if refresh.nil? + if refresh.nil? refresh = @redis.hget("#{@service_id}:oauth:access_token:#{access}",'refresh_token') end - + # delete tokens from redis @redis.multi do |multi| multi.del("#{@service_id}:oauth:access_token:#{access}") multi.del("#{@service_id}:oauth:refresh_token:#{refresh}") end @@ -280,11 +282,11 @@ end # # Obtain an 'access' and a 'refresh' token. # - # @param args check the authorize method o OAuth2 class + # @param args check the authorize method o OAuth2 class # @return hash with response content type and status code # def authorize (args) call do finalized(response: oauth2.authorize(args)) @@ -293,11 +295,11 @@ end # # Refresh an access token. # - # @param args check the refresh method o OAuth2 class + # @param args check the refresh method o OAuth2 class # @return hash with response content type and status code # def refresh (args) call do finalized(response: oauth2.refresh(args)) @@ -306,11 +308,11 @@ end # # Patch a pair of tokens, by generating new ones # - # @param args check the patch methods o OAuth2 class + # @param args check the patch methods o OAuth2 class # @return hash with response content type and status code # def patch (args) call do finalized(response: oauth2.patch(args)) @@ -319,14 +321,14 @@ end # # Remove a pair of tokens from redis. # - # @param args check the dispose method o OAuth2 class + # @param args check the dispose method o OAuth2 class # @return hash with response content type and status code # def dispose (args) - call do + call do finalized(response: oauth2.dispose(args)) end @output end