【问题标题】:Rails: Authentication with slack workspaceRails:使用松弛工作区进行身份验证
【发布时间】: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


    【解决方案1】:

    也许你需要放这样的东西

     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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 2015-10-05
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      相关资源
      最近更新 更多