Class: ShotgunApiRuby::Auth

Inherits:
Faraday::Middleware
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  raise 'missing auth' unless options[:auth]
  raise 'missing site_url' unless options[:site_url]
  unless Validator.valid?(**options[:auth]&.transform_keys(&:to_sym))
    raise 'Auth not valid'
  end

  super(app)

  @site_url = options[:site_url]
  @client_id = options[:auth][:client_id]
  @client_secret = options[:auth][:client_secret]
  @username = options[:auth][:username]
  @password = options[:auth][:password]
  @session_token = options[:auth][:session_token]
  @refresh_token = options[:auth][:refresh_token]
end

Instance Attribute Details

#client_idObject (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_secretObject (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

#passwordObject (readonly)

Returns the value of attribute password.



43
44
45
# File 'lib/shotgun_api_ruby/auth.rb', line 43

def password
  @password
end

#refresh_tokenObject (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_tokenObject (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_urlObject (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

#usernameObject (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_typeObject



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