17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/better_auth/sso/linking/types.rb', line 17
def normalized_profile(profile)
raw_attributes = raw_value(profile, :raw_attributes, "rawAttributes", "raw_attributes")
source = BetterAuth::Plugins.normalize_hash(profile || {})
normalized = {
provider_type: source[:provider_type].to_s,
provider_id: source[:provider_id].to_s,
account_id: source[:account_id].to_s,
email: source[:email].to_s.downcase,
email_verified: !!source[:email_verified]
}
normalized[:name] = source[:name] if source.key?(:name)
normalized[:image] = source[:image] if source.key?(:image)
normalized[:raw_attributes] = raw_attributes unless raw_attributes.nil?
missing = REQUIRED_PROFILE_KEYS.filter_map do |key, upstream_name|
value = normalized[key]
upstream_name if value.nil? || (value.respond_to?(:empty?) && value.empty?)
end
raise ArgumentError, "Missing normalized SSO profile fields: #{missing.join(", ")}" unless missing.empty?
raise ArgumentError, "Invalid normalized SSO profile providerType: #{normalized[:provider_type]}" unless BetterAuth::SSO::Types.provider_type?(normalized[:provider_type])
normalized.freeze
end
|