Class: RailsSso::App
- Inherits:
-
Object
- Object
- RailsSso::App
- Defined in:
- lib/rails_sso/app.rb
Instance Attribute Summary collapse
-
#provider_client ⇒ Object
readonly
Returns the value of attribute provider_client.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Instance Method Summary collapse
- #access_token ⇒ Object
- #fetch_user_data ⇒ Object
-
#initialize(strategy, session, provider_client) ⇒ App
constructor
A new instance of App.
- #invalidate_access_token! ⇒ Object
- #refresh_access_token! ⇒ Object
- #save_access_token!(access_token) ⇒ Object
Constructor Details
#initialize(strategy, session, provider_client) ⇒ App
Returns a new instance of App.
5 6 7 |
# File 'lib/rails_sso/app.rb', line 5 def initialize(strategy, session, provider_client) @strategy, @session, @provider_client = strategy, session, provider_client end |
Instance Attribute Details
#provider_client ⇒ Object (readonly)
Returns the value of attribute provider_client.
3 4 5 |
# File 'lib/rails_sso/app.rb', line 3 def provider_client @provider_client end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
3 4 5 |
# File 'lib/rails_sso/app.rb', line 3 def session @session end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
3 4 5 |
# File 'lib/rails_sso/app.rb', line 3 def strategy @strategy end |
Instance Method Details
#access_token ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rails_sso/app.rb', line 32 def access_token return token_mock if RailsSso.config.test_mode? OAuth2::AccessToken.new(strategy.client, session[:access_token], { refresh_token: session[:refresh_token] }) end |
#fetch_user_data ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rails_sso/app.rb', line 9 def fetch_user_data FetchUser.new(provider_client.token!(current_access_token_value)).call rescue ResponseError => e refresh_access_token! do FetchUser.new(provider_client.token!(current_access_token_value)).call end if e.code == :unauthenticated end |
#invalidate_access_token! ⇒ Object
40 41 42 43 44 |
# File 'lib/rails_sso/app.rb', line 40 def invalidate_access_token! if RailsSso.config.provider_sign_out_path access_token.delete(RailsSso.config.provider_sign_out_path) end end |
#refresh_access_token! ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rails_sso/app.rb', line 17 def refresh_access_token! save_access_token!(access_token.refresh!) yield if block_given? rescue ::OAuth2::Error nil rescue ResponseError => e nil if e.code == :unauthenticated end |
#save_access_token!(access_token) ⇒ Object
27 28 29 30 |
# File 'lib/rails_sso/app.rb', line 27 def save_access_token!(access_token) session[:access_token] = access_token.token session[:refresh_token] = access_token.refresh_token end |