본문 바로가기
카테고리 없음

zoom webhook verification with ruby on rails

by Junmannn 2025. 2. 25.
반응형
def zoom_verification
  request_signature = request.headers['X-ZM-Signature']
  request_timestamp = request.headers['X-ZM-Request-Timestamp']

  # Construct the message string
  message = "v0:#{request_timestamp}:#{request.body.read}"

  # Create hash for verification
  hash_for_verify = OpenSSL::HMAC.hexdigest('sha256', "YOUR_ZOOM_SECRET_TOKEN_HERE", message)
  expected_signature = "v0=#{hash_for_verify}"

  # Validate the request signature
  if request_signature == expected_signature
      if params[:event] == 'endpoint.url_validation'
          plain_token = params[:payload][:plainToken]
          hash_for_validate = OpenSSL::HMAC.hexdigest('sha256', "YOUR_ZOOM_SECRET_TOKEN_HERE", plain_token)
          Rails.logger.info "hash_for_validate : #{hash_for_validate}"

          response = {
          message: {
              plainToken: plain_token,
              encryptedToken: hash_for_validate
          },
          status: 200
          }
          render json: response[:message], status: response[:status]
      else
          # Your business logic here (e.g., API requests to Zoom or third parties)
          response = { message: 'Authorized request to Zoom Webhook sample.', status: 200 }
          render json: response, status: response[:status]
      end
  else
      response = { message: 'Unauthorized request to Zoom Webhook sample.', status: 401 }
      render json: response, status: response[:status]
  end
end

 

 

+ add the def zoom_verification as url in routes.rb and publish.

 

 

For other frameworks or languages, change a little bit on hashing. If that is too hard, just copy and paste to GPT or Perplexity or whatever and ask for code variation

 

반응형