provider.rb 741 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Authorization::Provider
  3. include Mixin::RequiredSubPaths
  4. attr_reader :auth_hash, :user, :info, :uid
  5. def initialize(auth_hash, user = nil)
  6. @auth_hash = auth_hash
  7. @uid = auth_hash['uid']
  8. @info = auth_hash['info'] || {}
  9. @user = user.presence || fetch_user
  10. end
  11. def name
  12. self.class.name.demodulize.underscore
  13. end
  14. private
  15. def fetch_user
  16. if Setting.get('auth_third_party_auto_link_at_inital_login')
  17. user = find_user
  18. return user if user.present?
  19. end
  20. User.create_from_hash!(auth_hash)
  21. end
  22. def find_user
  23. return if info['email'].nil?
  24. User.find_by(email: info['email'].downcase)
  25. end
  26. end