Class: GoToWebinar::Auth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/go_to_webinar/auth/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basic_auth_username: nil, basic_auth_password: nil, consumer_key: nil, secret_key: nil) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/go_to_webinar/auth/client.rb', line 11

def initialize(basic_auth_username: nil, basic_auth_password: nil, consumer_key: nil, secret_key: nil)
  config = GoToWebinar::Auth.configuration
  @redis = Redis.new(url: config.redis_url)
  @basic_auth_username = config.basic_auth_username
  @basic_auth_password = config.basic_auth_password
  @consumer_key = consumer_key || config.consumer_key
  @secret_key = secret_key || config.secret_key
  @site = config.site
  @authorize_url = config.authorize_url
  @authorize_optional_params = config.authorize_optional_params
  @token_url = config.token_url
  @auth_scheme = config.auth_scheme
  @oauth2_client = new_oauth2_client
end

Instance Attribute Details

#basic_auth_passwordObject

Returns the value of attribute basic_auth_password.



9
10
11
# File 'lib/go_to_webinar/auth/client.rb', line 9

def basic_auth_password
  @basic_auth_password
end

#basic_auth_usernameObject

Returns the value of attribute basic_auth_username.



9
10
11
# File 'lib/go_to_webinar/auth/client.rb', line 9

def basic_auth_username
  @basic_auth_username
end

#consumer_keyObject

Returns the value of attribute consumer_key.



9
10
11
# File 'lib/go_to_webinar/auth/client.rb', line 9

def consumer_key
  @consumer_key
end

#secret_keyObject

Returns the value of attribute secret_key.



9
10
11
# File 'lib/go_to_webinar/auth/client.rb', line 9

def secret_key
  @secret_key
end

Instance Method Details

#access_tokenObject



37
38
39
# File 'lib/go_to_webinar/auth/client.rb', line 37

def access_token
  @access_token || get_access_token_from_redis || get_new_access_token
end

#get_new_access_tokenObject



41
42
43
44
45
# File 'lib/go_to_webinar/auth/client.rb', line 41

def get_new_access_token
  token = oauth2_client.password.get_token(basic_auth_username, basic_auth_password)
  save_to_redis(token)
  @access_token = token
end

#new_oauth2_clientObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/go_to_webinar/auth/client.rb', line 26

def new_oauth2_client
  OAuth2::Client.new(
    consumer_key,
    secret_key,
    site: site,
    authorize_url: authorize_url,
    token_url: token_url,
    auth_scheme: auth_scheme
  )
end

#refresh_access_tokenObject



47
48
49
# File 'lib/go_to_webinar/auth/client.rb', line 47

def refresh_access_token
  @access_token = access_token&.refresh!
end