Class: ShotgridApiRuby::Auth
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- ShotgridApiRuby::Auth
- Extended by:
- T::Sig
- Defined in:
- lib/shotgrid_api_ruby/auth.rb
Overview
Faraday middleware responsible for authentication with the shotgrid site
Defined Under Namespace
Modules: Validator
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#session_token ⇒ Object
readonly
Returns the value of attribute session_token.
-
#site_url ⇒ Object
readonly
Returns the value of attribute site_url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #auth_type ⇒ Object
- #call(request_env) ⇒ Object
-
#initialize(app = nil, options = { auth: nil, site_url: nil }) ⇒ Auth
constructor
A new instance of Auth.
Constructor Details
#initialize(app = nil, options = { auth: nil, site_url: nil }) ⇒ Auth
Returns a new instance of Auth.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 50 def initialize(app = nil, = { auth: nil, site_url: nil }) raise 'missing auth' unless [:auth] raise 'missing site_url' unless [:site_url] unless Validator.valid?(**[:auth]&.transform_keys(&:to_sym)) raise 'Auth not valid' end @site_url = T.let([:site_url], String) @client_id = T.let([:auth][:client_id], T.nilable(String)) @client_secret = T.let([:auth][:client_secret], T.nilable(String)) @username = T.let([:auth][:username], T.nilable(String)) @password = T.let([:auth][:password], T.nilable(String)) @session_token = T.let([:auth][:session_token], T.nilable(String)) @refresh_token = T.let([:auth][:refresh_token], T.nilable(String)) @app = T.let( nil, T.nilable(T.any(Faraday::Middleware, VCR::Middleware::Faraday)), ) @auth_type = T.let(nil, T.nilable(String)) @auth_params = T.let(nil, T.nilable(String)) @auth_url = T.let(nil, T.nilable(String)) @access_token = T.let(nil, T.nilable(String)) @token_expiry = T.let(nil, T.nilable(Time)) super(app) end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
79 80 81 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 79 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
82 83 84 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 82 def client_secret @client_secret end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
91 92 93 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 91 def password @password end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
97 98 99 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 97 def refresh_token @refresh_token end |
#session_token ⇒ Object (readonly)
Returns the value of attribute session_token.
94 95 96 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 94 def session_token @session_token end |
#site_url ⇒ Object (readonly)
Returns the value of attribute site_url.
85 86 87 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 85 def site_url @site_url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
88 89 90 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 88 def username @username end |
Instance Method Details
#auth_type ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 100 def auth_type @auth_type ||= if refresh_token 'refresh_token' elsif client_id 'client_credentials' elsif username 'password' elsif session_token 'session_token' else '' end end |
#call(request_env) ⇒ Object
116 117 118 119 120 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 116 def call(request_env) request_env[:request_headers].merge!(std_headers) @app&.call(request_env) end |