Class: Aspera::Plugins::Shares::SharesWeb
- Inherits:
-
OAuth::Web
- Object
- OAuth::Base
- OAuth::Web
- Aspera::Plugins::Shares::SharesWeb
- Defined in:
- lib/aspera/plugins/shares/shares_web.rb
Overview
Authentication of a SAML user of Aspera Shares using a Web browser.
Shares has no OAuth authorization endpoint: the OAuth tokens of the user (same as those of <url>/auth/oauth2/token) are given by the SAML login page
(<url>/auth/saml), once the user is authenticated. The way depends on option ui.web_auth:
port(default):RelayStateis the loopback URL, Shares redirects the browser to it with the tokens in the query. It is automatic.paste:RelayStateisaspera://device-code?state=<state>, Shares shows a code that the user pastes in the terminal. No local port is used, the browser can be on any system. The refresh token received (in the URL, or in the code) is immediately exchanged for a new token: the tokens that went through the browser are not valid any more.
Constant Summary collapse
- DEVICE_CODE_RELAY_STATE =
RelayStatethat tells Shares to show the code (paste) 'aspera://device-code?state='
Constants inherited from OAuth::Web
Instance Attribute Summary
Attributes inherited from OAuth::Base
Instance Method Summary collapse
- #create_token ⇒ Object
-
#initialize(redirect_uri:, path_authorize: 'saml', **base_params) ⇒ SharesWeb
constructor
A new instance of SharesWeb.
Methods inherited from OAuth::Web
Methods inherited from OAuth::Base
absolute_url?, #authorization, #base_parameters, client_id_digest, #create_token_base, #endpoint_api, #endpoint_url, #renew_token, #renewed_authorization, #token
Constructor Details
#initialize(redirect_uri:, path_authorize: 'saml', **base_params) ⇒ SharesWeb
Returns a new instance of SharesWeb.
31 32 33 34 35 36 |
# File 'lib/aspera/plugins/shares/shares_web.rb', line 31 def initialize(redirect_uri:, path_authorize: 'saml', **base_params) # Shares needs a path in the loopback URL, and the local server expects it uri = URI.parse(redirect_uri) uri.path = '/' if uri.path.empty? super(redirect_uri: uri.to_s, path_authorize: , path_token: 'oauth2/token', **base_params) end |
Instance Method Details
#create_token ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/aspera/plugins/shares/shares_web.rb', line 38 def create_token # state is returned unchanged by Shares: it ties the answer to this login random_state = SecureRandom.uuid received_params = case Environment.instance.web_auth when :paste then receive_code(random_state) when :port then receive_on_loopback(random_state) else Aspera.error_unexpected_value(Environment.instance.web_auth) { 'ui.web_auth' } end Aspera.assert(random_state.eql?(received_params['state'])) { 'wrong received state' } refresh_token = received_params['refresh_token'].to_s Aspera.assert(!refresh_token.empty?) { 'No token received: does this Shares have the login patch for ascli?' } Secret::Hider.instance.add_secret_values(refresh_token, received_params['access_token'].to_s) create_token_base(grant_type: 'refresh_token', refresh_token: refresh_token) end |