Ruby on rails Rails:使用slack workspace进行身份验证
目前,我正在尝试将松弛集成添加到应用程序中。应用程序上的用户应在应用程序上发布的同时自动发布到自己的slack workspace GemRuby on rails Rails:使用slack workspace进行身份验证,ruby-on-rails,ruby,slack,Ruby On Rails,Ruby,Slack,目前,我正在尝试将松弛集成添加到应用程序中。应用程序上的用户应在应用程序上发布的同时自动发布到自己的slack workspace Gemomniauth\u slack允许它访问我自己拥有的工作区,但这不适用于其他工作区的身份验证 需要以下信息: *客户识别码 *范围 *重定向\u uri *陈述 *团队 像这样更新omniauth.rb Rails.application.config.middleware.use OmniAuth::Builder do provider :slack
omniauth\u slack
允许它访问我自己拥有的工作区,但这不适用于其他工作区的身份验证
需要以下信息:
*客户识别码
*范围
*重定向\u uri
*陈述
*团队
像这样更新omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :slack,
'CLIENT_ID',
scope: 'team:read,users:read,identify,bot',
token: "XXXXXXXXXXXXXXXXXXXXXX"
end
其他代码在这里
应用程序/控制器/slack\u控制器.rb
class SlackController < ApplicationController
def callback
p request.env['omniauth.auth'].info
redirect_to '/'
end
end
<%= link_to 'Slack authentication', '/auth/slack' %>
Rails.application.routes.draw do
root 'home#index'
get 'auth/:provider/callback' => 'slack#callback'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
config/routes.eb
class SlackController < ApplicationController
def callback
p request.env['omniauth.auth'].info
redirect_to '/'
end
end
<%= link_to 'Slack authentication', '/auth/slack' %>
Rails.application.routes.draw do
root 'home#index'
get 'auth/:provider/callback' => 'slack#callback'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
也许你需要放一些像这样的东西
Rails.application.config.middleware.use OmniAuth::Builder do
provider :slack,
ENV['CLIENT_ID'],
ENV['CLIENT_SECRET'],
scope:'chat:write,commands,im:write,users:read'
end
如果要使用Api方法,则需要使用令牌配置slack
class SlackMessages
def Initialize
Slack.configure do |config|
config.token = "xoxp-xxxxxx234234324..."
end
@client = ::Slack::Web::Client.new
end
def postmessage
@client.chat_postMessage(options)
end
end
创建一个名为slack的初始值设定项,并放置如下内容:
Slack::Events.configure do |config|
config.signing_secret = ENV['SIGNING_SECRET']
end