我有个问题。我有两个Rails网站,站点A和站点B。站点A是一个新闻网站,它使用设备作为身份验证系统,并使用带有单点登录的Disqus来评论内容。
网站B是另一个新闻网站,它没有任何用户身份验证系统,使用Disqus对内容进行评论,但没有单点登录。
我要允许站点A的用户在站点B的Disqus上进行SSO。Disqus SSO使用此脚本
def get_disqus_sso(user)
# create a JSON packet of our data attributes
data = {
'id' => user['id'],
'username' => user['username'],
'email' => user['email']
#'avatar' => user['avatar'],
#'url' => user['url']
}.to_json
# encode the data to base64
message = Base64.encode64(data).gsub("\n", "")
# generate a timestamp for signing the message
timestamp = Time.now.to_i
# generate our hmac signature
sig = OpenSSL::HMAC.hexdigest('sha1', DISQUS_SECRET_KEY, '%s %s' % [message, timestamp])
# return a script tag to insert the sso message
return "<script type=\"text/javascript\">
var disqus_config = function() {
this.page.remote_auth_s3 = \"#{message} #{sig} #{timestamp}\";
this.page.api_key = \"#{DISQUS_PUBLIC_KEY}\";
}
</script>"
end当然在站点B上我没有任何用户,我想在站点A上创建一个私有API,返回给一个登录的用户"#{message} #{sig} #{timestamp}\"
有没有可能创建一个API来返回一些东西,使用身份验证成功后由Devise创建的会话cookie作为身份验证方法?
发布于 2018-06-22 19:34:43
我认为使用jwt可以做到这一点。流程如下。(仅用子域名测试)
user uses siteA(stores generated jwt token in a cookie) --> siteB uses the jwt token in cookie --> sends token to siteA for user data --> gets user data.
jwt身份验证example
cookie注释:仅适用于子域,不要忘记签署cookie以防止篡改。
https://stackoverflow.com/questions/50966687
复制相似问题