Class: Chronicle::ETL::OauthAuthorizer
- Inherits:
-
Authorizer
- Object
- Authorizer
- Chronicle::ETL::OauthAuthorizer
- Defined in:
- lib/chronicle/etl/oauth_authorizer.rb
Overview
An authorization strategy that uses oauth2 (and omniauth under the hood)
Class Attribute Summary collapse
-
.authorization_to_secret_map ⇒ Object
readonly
Returns the value of attribute authorization_to_secret_map.
-
.client_id ⇒ Object
Returns the value of attribute client_id.
-
.client_secret ⇒ Object
Returns the value of attribute client_secret.
-
.provider_name ⇒ Object
readonly
Returns the value of attribute provider_name.
-
.strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Instance Attribute Summary collapse
-
#authorization ⇒ Object
readonly
Returns the value of attribute authorization.
Class Method Summary collapse
-
.all ⇒ Object
Returns all subclasses of OauthAuthorizer (Used by AuthorizationServer to build omniauth providers).
-
.omniauth_strategy(strategy) ⇒ Object
Macro for specifying which omniauth strategy to use.
-
.options ⇒ Object
Macro for specifying options to pass to omniauth.
-
.pluck_secrets(map) ⇒ Object
Macro for specifying hash of returned authorization to secrets hash.
-
.scope(value) ⇒ Object
Macro for specifying which omniauth scopes to request.
Instance Method Summary collapse
-
#authorize! ⇒ Object
Start up an authorization server and handle the oauth flow.
-
#initialize(port:, credentials: {}) ⇒ OauthAuthorizer
constructor
Create a new instance of OauthAuthorizer.
Methods inherited from Authorizer
Constructor Details
#initialize(port:, credentials: {}) ⇒ OauthAuthorizer
Create a new instance of OauthAuthorizer
42 43 44 45 46 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 42 def initialize(port:, credentials: {}) @port = port @credentials = credentials super end |
Class Attribute Details
.authorization_to_secret_map ⇒ Object (readonly)
Returns the value of attribute authorization_to_secret_map.
9 10 11 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 9 def @authorization_to_secret_map end |
.client_id ⇒ Object
Returns the value of attribute client_id.
10 11 12 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 10 def client_id @client_id end |
.client_secret ⇒ Object
Returns the value of attribute client_secret.
10 11 12 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 10 def client_secret @client_secret end |
.provider_name ⇒ Object (readonly)
Returns the value of attribute provider_name.
9 10 11 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 9 def provider_name @provider_name end |
.strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
9 10 11 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 9 def strategy @strategy end |
Instance Attribute Details
#authorization ⇒ Object (readonly)
Returns the value of attribute authorization.
39 40 41 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 39 def @authorization end |
Class Method Details
.all ⇒ Object
Returns all subclasses of OauthAuthorizer (Used by AuthorizationServer to build omniauth providers)
34 35 36 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 34 def all ObjectSpace.each_object(::Class).select { |klass| klass < self } end |
.omniauth_strategy(strategy) ⇒ Object
Macro for specifying which omniauth strategy to use
13 14 15 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 13 def omniauth_strategy(strategy) @strategy = strategy end |
.options ⇒ Object
Macro for specifying options to pass to omniauth
28 29 30 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 28 def @options ||= {} end |
.pluck_secrets(map) ⇒ Object
Macro for specifying hash of returned authorization to secrets hash
23 24 25 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 23 def pluck_secrets(map) @authorization_to_secret_map = map end |
.scope(value) ⇒ Object
Macro for specifying which omniauth scopes to request
18 19 20 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 18 def scope(value) [:scope] = value end |
Instance Method Details
#authorize! ⇒ Object
Start up an authorization server and handle the oauth flow
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chronicle/etl/oauth_authorizer.rb', line 49 def associate_oauth_credentials @server = load_server spinner = TTY::Spinner.new(':spinner :title', format: :dots_2) spinner.auto_spin spinner.update(title: "Starting temporary authorization server on port #{@port}"'') server_thread = (port: @port) start_oauth_flow spinner.update(title: 'Waiting for authorization to complete in your browser') sleep 0.1 while (server_thread) @server.quit! server_thread.join spinner.success("(#{'successful'.green})") # TODO: properly handle failed authorizations raise Chronicle::ETL::AuthorizationError unless @server. @authorization = @server. extract_secrets(authorization: @authorization, pluck_values: self.class.) end |