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 ⇒ String? readonly
- #client_secret ⇒ String? readonly
- #password ⇒ String? readonly
- #refresh_token ⇒ String? readonly
- #session_token ⇒ String? readonly
- #site_url ⇒ String readonly
- #username ⇒ String? readonly
Instance Method Summary collapse
- #auth_type ⇒ String
- #call(request_env) ⇒ Faraday::Response
- #initialize(app = nil, options = { auth: nil, site_url: nil }) ⇒ void constructor
Constructor Details
#initialize(app = nil, options = { auth: nil, site_url: nil }) ⇒ void
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 ⇒ String? (readonly)
79 80 81 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 79 def client_id @client_id end |
#client_secret ⇒ String? (readonly)
82 83 84 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 82 def client_secret @client_secret end |
#password ⇒ String? (readonly)
91 92 93 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 91 def password @password end |
#refresh_token ⇒ String? (readonly)
97 98 99 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 97 def refresh_token @refresh_token end |
#session_token ⇒ String? (readonly)
94 95 96 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 94 def session_token @session_token end |
#site_url ⇒ String (readonly)
85 86 87 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 85 def site_url @site_url end |
#username ⇒ String? (readonly)
88 89 90 |
# File 'lib/shotgrid_api_ruby/auth.rb', line 88 def username @username end |
Instance Method Details
#auth_type ⇒ String
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) ⇒ Faraday::Response
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 |