Sha256: 825d781b1e7bb5f945e0f974e00557944d62eb3c7c6ab999e54563b71a0babd6

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

# frozen_string_literal: true

require_relative "extension"

module SidekiqWebGoogleAuth
  class Builder < OmniAuth::Builder
    class ArgumentError < StandardError; end

    ARGUMENT_ERROR = "You must provide authorized_emails or authorized_emails_domains (or both)"

    def provider(*args, authorized_emails: [], authorized_emails_domains: [], **options, &block)
      invalid_arguments! if authorized_emails.empty? && authorized_emails_domains.empty?
      super("google_oauth2", *args, options.merge(name: "oauth"), &block)

      SidekiqWebGoogleAuth::Extension.authorized_emails = authorized_emails
      SidekiqWebGoogleAuth::Extension.authorized_emails_domains = authorized_emails_domains
      Sidekiq::Web.register(SidekiqWebGoogleAuth::Extension)
    end

    private

    def invalid_arguments!
      raise ArgumentError.new(ARGUMENT_ERROR)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq_web_google_auth-0.1.2 lib/sidekiq_web_google_auth/builder.rb