Class: OmniAuth::Strategies::Xivauth
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Xivauth
- Defined in:
- lib/omniauth/strategies/xivauth.rb
Constant Summary collapse
- DEFAULT_SCOPE =
'user'.freeze
- LODESTONE_CHARACTER_URL =
'https://na.finalfantasyxiv.com/lodestone/character/%s/'.freeze
Instance Method Summary collapse
- #authorize_params ⇒ Object
-
#character_data ⇒ Object
Fetched whenever the
characterscope was granted. - #character_only_login? ⇒ Boolean
- #character_scope_granted? ⇒ Boolean
-
#granted_scopes ⇒ Object
NOTE: assumes the token response echoes back the granted scope as a space-delimited
scopeparam, readable viaaccess_token.params. -
#primary_character ⇒ Object
The single character returned when
characterscope is granted withoutuserscope (the character-only sign-in flow). -
#user_data ⇒ Object
Only fetched when the
userscope was granted. - #user_scope_granted? ⇒ Boolean
Instance Method Details
#authorize_params ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/omniauth/strategies/xivauth.rb', line 107 def super.tap do |params| [:authorize_options].each do |option| params[option] = request.params[option.to_s] if request.params[option.to_s] end params[:scope] ||= DEFAULT_SCOPE end end |
#character_data ⇒ Object
Fetched whenever the character scope was granted.
93 94 95 96 97 |
# File 'lib/omniauth/strategies/xivauth.rb', line 93 def character_data return @character_data if defined?(@character_data) @character_data = access_token.get('characters').parsed if character_scope_granted? end |
#character_only_login? ⇒ Boolean
68 69 70 71 72 |
# File 'lib/omniauth/strategies/xivauth.rb', line 68 def character_only_login? # character and character:all are blocked by xivauth's server side, but we should still test for it. granted_scopes.include?('character') && !user_scope_granted? && !(granted_scopes.include?('character:all') || granted_scopes.include?('character:manage')) end |
#character_scope_granted? ⇒ Boolean
78 79 80 81 |
# File 'lib/omniauth/strategies/xivauth.rb', line 78 def character_scope_granted? granted_scopes.include?('character') || granted_scopes.include?('character:all') || granted_scopes.include?('character:manage') end |
#granted_scopes ⇒ Object
NOTE: assumes the token response echoes back the granted scope as a
space-delimited scope param, readable via access_token.params.
61 62 63 64 65 66 |
# File 'lib/omniauth/strategies/xivauth.rb', line 61 def granted_scopes return @granted_scopes if defined?(@granted_scopes) scope = access_token.params && access_token.params['scope'] @granted_scopes = scope.to_s.split end |
#primary_character ⇒ Object
The single character returned when character scope is granted
without user scope (the character-only sign-in flow).
101 102 103 104 105 |
# File 'lib/omniauth/strategies/xivauth.rb', line 101 def primary_character return nil if user_scope_granted? || !character_scope_granted? character_data&.first end |
#user_data ⇒ Object
Only fetched when the user scope was granted. The user:email
scope only adds fields to this same payload, it doesn't change
whether the request is made.
86 87 88 89 90 |
# File 'lib/omniauth/strategies/xivauth.rb', line 86 def user_data return @user_data if defined?(@user_data) @user_data = user_scope_granted? ? access_token.get('user').parsed : nil end |
#user_scope_granted? ⇒ Boolean
74 75 76 |
# File 'lib/omniauth/strategies/xivauth.rb', line 74 def user_scope_granted? granted_scopes.include?('user') || granted_scopes.include?('user:manage') end |