Class: Aspera::Cli::Plugins::Oauth
- Defined in:
- lib/aspera/cli/plugins/oauth.rb
Overview
base class for applications supporting OAuth 2.0 authentication
Constant Summary collapse
- AUTH_TYPES =
OAuth methods supported
i[web jwt boot].freeze
- AUTH_OPTIONS =
Options used for authentication
i[url auth client_id client_secret scope redirect_uri private_key passphrase username password].freeze
Constants inherited from Base
Base::ALL_OPS, Base::GLOBAL_OPS, Base::INSTANCE_OPS, Base::MAX_ITEMS, Base::MAX_PAGES, Base::REGEX_LOOKUP_ID_BY_FIELD
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(**_) ⇒ Oauth
constructor
A new instance of Oauth.
-
#new_with_options(klass, base: {}, add: {}) ⇒ Object
Get all options specified by AUTH_OPTIONS and add.keys Adds those not nil to the ‘base`.
Methods inherited from BasicAuth
#basic_auth_api, #basic_auth_params, declare_options
Methods inherited from Base
#add_manual_header, #config, declare_options, #do_bulk_operation, #entity_execute, #formatter, #instance_identifier, #list_entities_limit_offset_total_count, #lookup_entity_by_field, #options, #persistency, #query_read_delete, #transfer, #value_create_modify
Constructor Details
#initialize(**_) ⇒ Oauth
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/aspera/cli/plugins/oauth.rb', line 14 def initialize(**_) super .declare(:auth, 'OAuth type of authentication', values: AUTH_TYPES, default: :jwt) .declare(:client_id, 'OAuth client identifier') .declare(:client_secret, 'OAuth client secret') .declare(:redirect_uri, 'OAuth (Web) redirect URI for web authentication') .declare(:private_key, 'OAuth (JWT) RSA private key PEM value (prefix file path with @file:)') .declare(:passphrase, 'OAuth (JWT) RSA private key passphrase') .declare(:scope, 'OAuth scope for API calls') end |
Instance Method Details
#new_with_options(klass, base: {}, add: {}) ⇒ Object
Get all options specified by AUTH_OPTIONS and add.keys Adds those not nil to the ‘base`. Instantiate the provided `klass` with those kwargs. `add` can specify a default value (not `nil`)
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aspera/cli/plugins/oauth.rb', line 32 def (klass, base: {}, add: {}) klass.new(** (AUTH_OPTIONS + add.keys).each_with_object(base) do |i, m| v = .get_option(i) m[i] = v unless v.nil? m[i] = add[i] unless !m[i].nil? || add[i].nil? end) rescue ::ArgumentError => e if (m = e..match(/missing keyword: :(.*)$/)) raise Cli::Error, "Missing option: #{m[1]}" end raise end |