class Doyoubuzz::Showcase::SSO

Constants

BASE_URL

Attributes

application[R]
key[R]

Public Class Methods

new(application, key) click to toggle source
# File lib/doyoubuzz/showcase/sso.rb, line 7
def initialize(application, key)
  @application = application
  @key = key
end

Public Instance Methods

redirect_url(locale: 'fr', timestamp:, user_attributes:) click to toggle source
# File lib/doyoubuzz/showcase/sso.rb, line 12
def redirect_url(locale: 'fr', timestamp:, user_attributes:)
  enforce_sso_attributes(user_attributes)

  params = sign_params(user_attributes.merge(timestamp: timestamp))
  encoded_params = URI.encode_www_form(params)

  "#{BASE_URL}/p/#{locale}/#{application}/sso?#{encoded_params}"
end

Private Instance Methods

enforce_sso_attributes(attributes) click to toggle source
# File lib/doyoubuzz/showcase/sso.rb, line 25
def enforce_sso_attributes(attributes)
  required = %i(email external_id firstname lastname)
  missing = required.reject { |key| attributes[key] }

  raise(
    ArgumentError,
    "Missing mandatory attributes for SSO : #{missing.join(', ')}"
  ) if missing.any?
end
sign_params(params) click to toggle source
# File lib/doyoubuzz/showcase/sso.rb, line 35
def sign_params(params)
  # Custom ordering
  tosign = params.values_at(
    :email,
    :firstname,
    :lastname,
    :external_id,
    :"group[]",
    :user_type,
    :timestamp
  ).compact.join + key

  params.merge(hash: Digest::MD5.hexdigest(tosign))
end