Gema de inicio de sesión único de Zendesk para rails 3

¿Alguien sabe de una gema mantenida que maneje la autenticación de usuarios para la API de Zendesk a través de una aplicación Rails 3 existente?

Le pregunté a Zendesk IT y me enviaron a, pero no parece compatible con los rieles 3 y no se ha actualizado desde 2009.

preguntado el 10 de mayo de 11 a las 13:05

2 Respuestas

Creo que el artículo de nuestros documentos da la impresión de que Zendesk SSO es difícil cuando en realidad es bastante fácil (

# reference
# you need to be a Zendesk account admin to enable remote auth (if you have not already)
# go to Settings > Security, click "Enabled" next to Single Sign-On

# three important things to pay attention to:
# Remote Login URL, Remote Logout URL, and shared secret token

# for testing on a Rails 3 application running on localhost, fill in the Remote Login URL to map
# to http://localhost:3000/zendesk/login (we will need to make sure routes for that exist)

# fill in Remote Logout URL to http://localhost:3000/zendesk/logout

# copy the secret token, you'll need it later

# first, let's create those routes in config/routes.rb
namespace :zendesk do
  match "/login" => "zendesk#login"    # will match /zendesk/login
  match "/logout" => "zendesk#logout"  # will match /zendesk/logout

# Above I've mapped those requests to a controller named "zendesk" but it can be named anything

# next we want to add our secret token to the application, I added this in an initializer
# config/initializers/zendesk_auth.rb
ZENDESK_REMOTE_AUTH_TOKEN = "< your token >"

# Assuming we have a controller called zendesk, in zendesk_controller.rb

require "digest/md5"
class ZendeskController < ApplicationController

  def index
    @zendesk_remote_auth_url = ZENDESK_REMOTE_AUTH_URL

  def login
    timestamp = params[:timestamp] ||
    # hard coded for example purposes
    # really you would want to do something like and
    # and you'd probably want this in a helper to hide all this implementation from the controller
    string = "First Last" + "" + ZENDESK_REMOTE_AUTH_TOKEN + timestamp.to_s
    hash = Digest::MD5.hexdigest(string)
    @zendesk_remote_auth_url = "{timestamp}&hash=#{hash}"
    redirect_to @zendesk_remote_auth_url

  def logout
    flash[:notice] = params[:message]

# Note that the above index action defines an instance variable @zendesk_remote_auth_url
# in my example I simple put a link on the corresponding view that hits ZENDESK_REMOTE_AUTH_URL, doing so
# will cause Zendesk to hit your applications Remote Login URL (you defined in your Zendesk SSO settings) and pass a timestamp back in the URL parameters
# BUT, it is entirely possible to avoid this extra step if you just want to go to /zendesk/login in your app
# notice I am either using a params[:timestamp] if one exists or creating a new timestamp with

Este ejemplo es bastante simplista, pero solo quiero ilustrar la mecánica básica de Zendesk SSO. Tenga en cuenta que no estoy tocando el tema más complicado de crear nuevos usuarios o editar los existentes, solo iniciar sesión en usuarios que tienen una cuenta de Zendesk existente.

contestado el 19 de mayo de 11 a las 22:05

Zendesk::RemoteAuth.auth_url = '' Zendesk::RemoteAuth.token = 'blah8blah' - chaserx

Además, Zendesk ahora requiere un hash con tuberías que separan los parámetros incluidos en la URL. input = name + "|" + email + "|" + external_id + "|" + organization + "|" + tags + "|" + remote_photo_url + "|" + token + "|" + timestamp hash = md5(input) - chaserx

actualizado: Zendesk está desaprobando el sistema de autenticación remota a favor de un nuevo enfoque basado en JSON Web Tokens:… - Jacob Mattison

Hay un código de ejemplo actualizado de zendesk

# Using JWT from Ruby is straight forward. The below example expects you to have `jwt`
# in your Gemfile, you can read more about that gem at
# Assuming that you've set your shared secret and Zendesk subdomain in the environment, you
# can use Zendesk SSO from your controller like this example.

class ZendeskSessionController < ApplicationController
  # Configuration

  def create
    if user = User.authenticate(params[:login], params[:password])
      # If the submitted credentials pass, then log user into Zendesk
      render :new, :notice => "Invalid credentials"


  def sign_into_zendesk(user)
    # This is the meat of the business, set up the parameters you wish
    # to forward to Zendesk. All parameters are documented in this page.
    iat =
    jti = "#{iat}/#{rand(36**64).to_s(36)}"

    payload = JWT.encode({
      :iat   => iat, # Seconds since epoch, determine when this token is stale
      :jti   => jti, # Unique token id, helps prevent replay attacks
      :name  =>,
      :email =>,

    redirect_to zendesk_sso_url(payload)

  def zendesk_sso_url(payload)

Respondido el 06 de junio de 13 a las 12:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.