2020-03-25 17:45:53 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# OAuth2Provider is a special type of AuthProvider which provides authentication through an external SSO server using
|
|
|
|
# the oAuth 2.0 protocol.
|
2020-03-25 10:16:47 +01:00
|
|
|
class OAuth2Provider < ApplicationRecord
|
2016-03-23 18:39:41 +01:00
|
|
|
has_one :auth_provider, as: :providable
|
|
|
|
has_many :o_auth2_mappings, dependent: :destroy
|
|
|
|
accepts_nested_attributes_for :o_auth2_mappings, allow_destroy: true
|
|
|
|
|
|
|
|
def domain
|
2021-11-10 13:03:12 +01:00
|
|
|
URI(base_url).scheme + '://' + URI(base_url).host
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def protected_fields
|
|
|
|
fields = []
|
|
|
|
o_auth2_mappings.each do |mapping|
|
2021-11-10 13:03:12 +01:00
|
|
|
fields.push(mapping.local_model + '.' + mapping.local_field)
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
fields
|
|
|
|
end
|
|
|
|
end
|