lib/mrkt/concerns/authentication.rb in mrkt-0.4.0 vs lib/mrkt/concerns/authentication.rb in mrkt-0.5.0

- old
+ new

@@ -12,23 +12,25 @@ def valid_token? @valid_until && Time.now < @valid_until end def authenticate - params = { - grant_type: 'client_credentials', - client_id: @client_id, - client_secret: @client_secret - } - - connection.get('/identity/oauth/token', params).tap do |response| + connection.get('/identity/oauth/token', authentication_params).tap do |response| data = response.body @token = data.fetch(:access_token) @token_type = data.fetch(:token_type) @valid_until = Time.now + data.fetch(:expires_in) @scope = data.fetch(:scope) end + end + + def authentication_params + { + grant_type: 'client_credentials', + client_id: @client_id, + client_secret: @client_secret + } end def add_authorization(req) req.headers[:authorization] = "Bearer #{@token}" end