Class: Aspera::OAuth::JsonCredentials

Inherits:
Base
  • Object
show all
Defined in:
lib/aspera/oauth/client/json_credentials.rb

Overview

Token creator using JSON credentials (e.g., username/password or apikey) sent to a login endpoint

Instance Attribute Summary

Attributes inherited from Base

#api, #params, #path_token

Instance Method Summary collapse

Methods inherited from Base

absolute_url?, #authorization, #base_parameters, client_id_digest, #create_token_base, #endpoint_api, #endpoint_url, #renew_token, #renewed_authorization, #token

Constructor Details

#initialize(json:, **generic_params) ⇒ JsonCredentials

Returns a new instance of JsonCredentials.

Parameters:

  • json (Hash) —

    Body parameters to send as JSON (e.g. password: or apikey:)

  • generic_params (Hash) —

    Generic parameters for OAuth::Base



15
16
17
18
19
20
21
22
# File 'lib/aspera/oauth/client/json_credentials.rb', line 15

def initialize(
  json:,
  **generic_params
)
  cache_id = json[:username] || Digest::SHA256.hexdigest(json[:apikey] || json.to_s)[0..23]
  super(**generic_params, cache_ids: [cache_id])
  @body = json
end

Instance Method Details

#create_token ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aspera/oauth/client/json_credentials.rb', line 24

def create_token
  token_api, subpath = endpoint_api(path_token)
  token_api.call(
    operation:    'POST',
    subpath:      subpath,
    content_type: Mime::JSON,
    body:         @body,
    headers:      {'Accept' => Mime::JSON},
    ret:          :resp
  )
end