2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-23 02:20:43 -04:00
|
|
|
# this class is used by the user and omniauth controllers, it controls how
|
2013-08-25 21:04:16 -04:00
|
|
|
# an authentication system interacts with our database and middleware
|
2013-08-23 02:20:43 -04:00
|
|
|
|
|
|
|
class Auth::Authenticator
|
2018-07-23 11:51:57 -04:00
|
|
|
def name
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def enabled?
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
# run once the user has completed authentication on the third party system. Should return an instance of Auth::Result.
|
|
|
|
# If the user has requested to connect an existing account then `existing_account` will be set
|
|
|
|
def after_authenticate(auth_options, existing_account: nil)
|
2013-08-23 02:20:43 -04:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2013-09-24 09:17:57 -04:00
|
|
|
# can be used to hook in after the authentication process
|
2013-08-23 02:20:43 -04:00
|
|
|
# to ensure records exist for the provider in the db
|
|
|
|
# this MUST be implemented for authenticators that do not
|
|
|
|
# trust email
|
|
|
|
def after_create_account(user, auth)
|
|
|
|
# not required
|
|
|
|
end
|
|
|
|
|
2013-08-25 21:04:16 -04:00
|
|
|
# hook used for registering omniauth middleware,
|
|
|
|
# without this we can not authenticate
|
|
|
|
def register_middleware(omniauth)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2018-07-23 11:51:57 -04:00
|
|
|
|
|
|
|
# return a string describing the connected account
|
|
|
|
# for a given user (typically email address). Used to list
|
|
|
|
# connected accounts under the user's preferences. Empty string
|
|
|
|
# indicates not connected
|
|
|
|
def description_for_user(user)
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
2019-07-17 07:34:02 -04:00
|
|
|
# return a string describing the connected account
|
|
|
|
# for a given OmniAuth::AuthHash. Used in the confirmation screen
|
|
|
|
# when connecting accounts
|
|
|
|
def description_for_auth_hash(user)
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
2018-07-23 11:51:57 -04:00
|
|
|
# can authorisation for this provider be revoked?
|
|
|
|
def can_revoke?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2021-05-20 23:37:17 -04:00
|
|
|
# can existing discourse users connect this provider to their accounts
|
2018-07-23 11:51:57 -04:00
|
|
|
def can_connect_existing_user?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
# optionally implement the ability for users to revoke
|
|
|
|
# their link with this authenticator.
|
|
|
|
# should ideally contact the third party to fully revoke
|
|
|
|
# permissions. If this fails, return :remote_failed.
|
|
|
|
# skip remote if skip_remote == true
|
|
|
|
def revoke(user, skip_remote: false)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2013-08-23 02:20:43 -04:00
|
|
|
end
|