いつもお世話になっております。
作成しているアプリにslack連携を追加したいと考えています。
具体的には、アプリ内でユーザーが投稿したものと同一の内容を、ユーザーが指定したワークスペースのチャンネルにも登録したいです。
omniauth_slack
を使って、作成済みのワークスペース(チーム)と連携するところまではできたのですが、ワークスペースを選ぶ画面を作成することができません。
Oauth 2.0を通さなければならないということで、下記の情報をリダイレクトに入れようとしました。
client_id - issued when you created your app (required) scope - permissions to request (see below) (required) redirect_uri - URL to redirect back to (see below) (optional) state - unique string to be passed back upon completion (optional) team - Slack team ID of a workspace to attempt to restrict to (optional)
config/initializers/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
Ruby
1class SlackController < ApplicationController 2 def callback 3 p request.env['omniauth.auth'].info 4 redirect_to '/' 5 end 6end
apps/views/home/index.html.erb
Ruby
1<%= link_to 'Slack authentication', '/auth/slack' %>
Gemfile
Ruby
1gem 'omniauth-slack'
config/routes.rb
Ruby
1Rails.application.routes.draw do 2 root 'home#index' 3 get 'auth/:provider/callback' => 'slack#callback' 4 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 5end
お知恵を拝借させていただければと思います。
あなたの回答
tips
プレビュー