Class: OmniAuth::Strategies::Xivauth

Inherits:
OAuth2
  • Object
show all
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

Instance Method Details

#authorize_paramsObject



107
108
109
110
111
112
113
114
115
# File 'lib/omniauth/strategies/xivauth.rb', line 107

def authorize_params
  super.tap do |params|
    options[: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_dataObject

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

Returns:

  • (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

Returns:

  • (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_scopesObject

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_characterObject

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_dataObject

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

Returns:

  • (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