Class: Lt::Google::Api::Auth::Service
- Inherits:
-
Object
- Object
- Lt::Google::Api::Auth::Service
- Defined in:
- lib/lt/google/api/auth/service.rb
Constant Summary collapse
- REDIS_PREFIX =
'lt-google-api'
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #authorization_url ⇒ Object
- #authorizer ⇒ Object
- #credentials ⇒ Object
-
#initialize(context, options = {}) ⇒ Service
constructor
A new instance of Service.
- #user_id ⇒ Object
Constructor Details
#initialize(context, options = {}) ⇒ Service
Returns a new instance of Service.
33 34 35 36 |
# File 'lib/lt/google/api/auth/service.rb', line 33 def initialize(context, = {}) @context = context @options = end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
31 32 33 |
# File 'lib/lt/google/api/auth/service.rb', line 31 def context @context end |
Class Method Details
.authorizer_for(callback_path) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/lt/google/api/auth/service.rb', line 16 def (callback_path) @authorizer_for ||= begin client_id = ::Google::Auth::ClientId.new(ENV['GOOGLE_OAUTH2_CLIENT_ID'], ENV['GOOGLE_OAUTH2_CLIENT_SECRET']) token_store ||= ::Google::Auth::Stores::RedisTokenStore.new(redis: redis) scope = %w(https://www.googleapis.com/auth/drive) ::Google::Auth::WebUserAuthorizer.new(client_id, scope, token_store, callback_path) end end |
.redis ⇒ Object
26 27 28 |
# File 'lib/lt/google/api/auth/service.rb', line 26 def redis Rails.application.config.redis end |
Instance Method Details
#authorization_url ⇒ Object
38 39 40 |
# File 'lib/lt/google/api/auth/service.rb', line 38 def . @options.merge(request: context.request) end |
#authorizer ⇒ Object
42 43 44 |
# File 'lib/lt/google/api/auth/service.rb', line 42 def self.class.(@options[:callback_path]) end |
#credentials ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/lt/google/api/auth/service.rb', line 46 def credentials @credentials ||= begin remove_expired_token .get_credentials(user_id, context.request) end rescue StandardError => e Rails.logger.warn e. nil end |
#user_id ⇒ Object
56 57 58 |
# File 'lib/lt/google/api/auth/service.rb', line 56 def user_id @user_id ||= "#{REDIS_PREFIX}::#{context.current_user.try(:id)}@#{context.request.remote_ip}" end |