module SimpleGoogleAuth::Controller
Protected Instance Methods
google_auth_data()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 14 def google_auth_data return unless cached_google_auth_data if should_refresh_google_auth_data? refresh_google_auth_data end cached_google_auth_data end
google_authentication_uri()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 9 def google_authentication_uri state = session[SimpleGoogleAuth.config.state_session_key_name] = SimpleGoogleAuth.config.authentication_uri_state_builder.call(request) SimpleGoogleAuth::AuthorizationUriBuilder.new(state).uri end
redirect_if_not_google_authenticated()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 5 def redirect_if_not_google_authenticated redirect_to google_authentication_uri if google_auth_data.nil? end
Private Instance Methods
cached_google_auth_data()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 33 def cached_google_auth_data @_google_auth_data_presenter ||= google_auth_data_from_session end
google_auth_data_from_session()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 37 def google_auth_data_from_session if auth_data = session[SimpleGoogleAuth.config.data_session_key_name] AuthDataPresenter.new(auth_data) end rescue AuthDataPresenter::InvalidAuthDataError end
google_auth_data_stale?()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 48 def google_auth_data_stale? expiry_time = cached_google_auth_data["expires_at"] expiry_time.nil? || Time.parse(expiry_time).past? end
refresh_google_auth_data()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 25 def refresh_google_auth_data api = SimpleGoogleAuth::OAuth.new(SimpleGoogleAuth.config) auth_data = api.refresh_auth_token!(cached_google_auth_data["refresh_token"]) session[SimpleGoogleAuth.config.data_session_key_name] = auth_data @_google_auth_data_presenter = nil end
should_refresh_google_auth_data?()
click to toggle source
# File lib/simple_google_auth/controller.rb, line 44 def should_refresh_google_auth_data? SimpleGoogleAuth.config.refresh_stale_tokens && google_auth_data_stale? end