Module: Webhooks::Vendors::Concerns::Authentication
- Included in:
- SevenRooms::CallbackController
- Defined in:
- app/controllers/webhooks/vendors/concerns/authentication.rb
Instance Method Summary collapse
-
#authentication ⇒ Boolean
Authenticates the request by checking the presence and validity of the client id and client secret.
-
#find_client_application ⇒ Doorkeeper::Application
Finds the client application based on the provided client ID and client secret from the request headers.
Instance Method Details
#authentication ⇒ Boolean
Authenticates the request by checking the presence and validity of the client id and client secret. If either the client id or client secret is missing, it returns an unauthorized response. If the client id or client secret is invalid, it returns an unauthorized response. If the client id and client secret are present and valid, it returns true.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/webhooks/vendors/concerns/authentication.rb', line 10 def authentication client_id = request.headers['X-HungryHub-Client-Id'] client_secret = request.headers['X-HungryHub-Client-Secret'] if client_id.blank? || client_secret.blank? render json: { success: false, message: 'Missing client id or client secret', data: nil }, status: :unauthorized return false end unless valid_client?(client_id, client_secret) render json: { success: false, message: 'Invalid client id or client secret', data: nil }, status: :unauthorized return false end true end |
#find_client_application ⇒ Doorkeeper::Application
Finds the client application based on the provided client ID and client secret from the request headers.
32 33 34 35 36 37 |
# File 'app/controllers/webhooks/vendors/concerns/authentication.rb', line 32 def find_client_application client_id = request.headers['X-HungryHub-Client-Id'] client_secret = request.headers['X-HungryHub-Client-Secret'] Doorkeeper::Application.find_by(uid: client_id, secret: client_secret) end |