gpt4 book ai didi

ruby-on-rails - 适用于 rails 3 的 Zendesk Single Sign-on gem

转载 作者:行者123 更新时间:2023-12-01 08:39:16 26 4
gpt4 key购买 nike

有谁知道通过现有 Rails 3 应用程序处理 Zendesk API 用户身份验证的维护 gem?

我询问了 Zendesk IT 并被发送到 https://github.com/tobias/zendesk_remote_auth ,但它看起来与 rails 3 不兼容,并且自 2009 年以来未更新。

最佳答案

我认为我们文档中的文章给人的印象是 Zendesk SSO 很难,而实际上它很容易 (http://www.zendesk.com/api/remote-authentication)。

# reference http://www.zendesk.com/api/remote-authentication
# 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
end

# 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 >"
ZENDESK_REMOTE_AUTH_URL = "http://yourcompany.zendesk.com/access/remote/"

# 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
end

def login
timestamp = params[:timestamp] || Time.now.utc.to_i
# hard coded for example purposes
# really you would want to do something like current_user.name and current_user.email
# and you'd probably want this in a helper to hide all this implementation from the controller
string = "First Last" + "first.last@gmail.com" + ZENDESK_REMOTE_AUTH_TOKEN + timestamp.to_s
hash = Digest::MD5.hexdigest(string)
@zendesk_remote_auth_url = "http://yourcompany.zendesk.com/access/remote/?name=First%20Last&email=first.last@gmail.com&timestamp=#{timestamp}&hash=#{hash}"
redirect_to @zendesk_remote_auth_url
end

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

# 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 Time.now

这个例子非常简单,但我只是想说明 Zendesk SSO 的基 native 制。请注意,我并没有涉及创建新用户或编辑现有用户的更复杂的问题,只是登录拥有现有 Zendesk 帐户的用户。

关于ruby-on-rails - 适用于 rails 3 的 Zendesk Single Sign-on gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5950866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com