【发布时间】:2020-03-10 06:15:02
【问题描述】:
目前我正在尝试将 Slack 集成添加到应用程序中。应用上的用户应该在应用上发布的同时自动发布到他们自己的松弛工作区。
Gem omniauth_slack 使其可以访问我自己拥有的工作区,但这不适用于与其他工作区进行身份验证。
The authentication for workspace 需要以下信息: * client_id * 范围 * 重定向 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
其他代码在这里。
apps/controllers/slack_controller.rb
class SlackController < ApplicationController
def callback
p request.env['omniauth.auth'].info
redirect_to '/'
end
end
apps/views/home/index.html.erb
<%= link_to 'Slack authentication', '/auth/slack' %>
宝石文件
gem 'omniauth-slack'
config/routes.eb
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
【问题讨论】:
标签: ruby-on-rails ruby slack