Rails:具有松弛工作空间的身份验证

问题描述 投票:0回答:1

当前,我正在尝试将Slack集成添加到应用程序中。应用程序上的用户应同时在应用程序上发布,同时自动发布到他们自己的松弛工作区。

Gem omniauth_slack使其可以访问我自己拥有的工作区,但这不适用于与其他工作区进行身份验证。

The authentication for workspace需要以下信息:* client_id* 范围* redirect_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' %>

Gemfile

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
1个回答
0
投票

也许您需要放置这样的东西

 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方法,则需要使用令牌配置松弛度

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
© www.soinside.com 2019 - 2024. All rights reserved.