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:, basic_auth_password:, consumer_key:, secret_key:) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/go_to_webinar/auth/client.rb', line 8

def initialize(basic_auth_username:, basic_auth_password:, consumer_key:, secret_key:)
  config = GoToWebinar::Auth.configuration
  @redis = Redis.new(url: config.redis_url)
  @basic_auth_username = basic_auth_username || config.basic_auth_username
  @basic_auth_password = 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
  @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.



6
7
8
# File 'lib/go_to_webinar/auth/client.rb', line 6

def basic_auth_password
  @basic_auth_password
end

#basic_auth_usernameObject

Returns the value of attribute basic_auth_username.



6
7
8
# File 'lib/go_to_webinar/auth/client.rb', line 6

def basic_auth_username
  @basic_auth_username
end

#consumer_keyObject

Returns the value of attribute consumer_key.



6
7
8
# File 'lib/go_to_webinar/auth/client.rb', line 6

def consumer_key
  @consumer_key
end

#secret_keyObject

Returns the value of attribute secret_key.



6
7
8
# File 'lib/go_to_webinar/auth/client.rb', line 6

def secret_key
  @secret_key
end

Instance Method Details

#access_tokenObject



33
34
35
# File 'lib/go_to_webinar/auth/client.rb', line 33

def access_token
  @access_token || get_access_token_from_redis || get_new_access_token
end

#get_new_access_tokenObject



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

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



22
23
24
25
26
27
28
29
30
31
# File 'lib/go_to_webinar/auth/client.rb', line 22

def new_oauth2_client
  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



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

def refresh_access_token
  @access_token = access_token&.refresh!
end