Class: ShotgunApiRuby::Auth
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- ShotgunApiRuby::Auth
- Defined in:
- lib/shotgun_api_ruby/auth.rb
Overview
Faraday middleware responsible for authentication with the shotgun 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
constructor
A new instance of Auth.
Constructor Details
#initialize(app = nil, options = {}) ⇒ Auth
Returns a new instance of Auth.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/shotgun_api_ruby/auth.rb', line 25 def initialize(app = 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 super(app) @site_url = [:site_url] @client_id = [:auth][:client_id] @client_secret = [:auth][:client_secret] @username = [:auth][:username] @password = [:auth][:password] @session_token = [:auth][:session_token] @refresh_token = [:auth][:refresh_token] end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
43 44 45 |
# File 'lib/shotgun_api_ruby/auth.rb', line 43 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
43 44 45 |
# File 'lib/shotgun_api_ruby/auth.rb', line 43 def client_secret @client_secret end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
43 44 45 |
# File 'lib/shotgun_api_ruby/auth.rb', line 43 def password @password end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
43 44 45 |
# File 'lib/shotgun_api_ruby/auth.rb', line 43 def refresh_token @refresh_token end |
#session_token ⇒ Object (readonly)
Returns the value of attribute session_token.
43 44 45 |
# File 'lib/shotgun_api_ruby/auth.rb', line 43 def session_token @session_token end |
#site_url ⇒ Object (readonly)
Returns the value of attribute site_url.
43 44 45 |
# File 'lib/shotgun_api_ruby/auth.rb', line 43 def site_url @site_url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
43 44 45 |
# File 'lib/shotgun_api_ruby/auth.rb', line 43 def username @username end |
Instance Method Details
#auth_type ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shotgun_api_ruby/auth.rb', line 51 def auth_type @auth_type ||= begin if refresh_token 'refresh_token' elsif client_id 'client_credentials' elsif username 'password' elsif session_token 'session_token' end end end |
#call(request_env) ⇒ Object
66 67 68 69 70 |
# File 'lib/shotgun_api_ruby/auth.rb', line 66 def call(request_env) request_env[:request_headers].merge!(std_headers) @app.call(request_env) end |