Rails 与 Slack 整合指南 (1)

栏目: Ruby · 发布时间: 6年前

内容简介:整理一下之前的 Slack 整合笔记。接 Slack 还是有挺多坑的。这篇主要写登入整合。整合 slack 主要靠三个 gem把 devise 先跑起来,然后 view 也下载下来

整理一下之前的 Slack 整合笔记。接 Slack 还是有挺多坑的。这篇主要写登入整合。

整合 slack 主要靠三个 gem deviseomniauthomniauth-slack

安装 devise

  • bundle install devise
  • rails g devise:install
  • rails g devise user
  • rails g devise:views

把 devise 先跑起来,然后 view 也下载下来

安装 omniauth

  • bundle install omniauth
  • user model 挂上 omniauthable
Rails 与 Slack 整合指南 (1)

安装 omniauth-slack

Rails 与 Slack 整合指南 (1)
  • 设定权限。记得要特别设 identity.email 才拿得到 email
config/initiailizers/devise.rb
config.omniauth :slack, ENV['SLACK_APP_ID'], ENV['SLACK_APP_SECRET'], scope: 'identity.basic,identity.email'   # 用 identity.email 能拿到 email

  config.omniauth :slack, ENV['SLACK_APP_ID'], ENV['SLACK_APP_SECRET'], scope: 'team:read,users:read'

设定 callbacks 网址

Rails 与 Slack 整合指南 (1)

记得要设 callbacks

Rails App 怎么接进来的资料

config/routes.rb
Rails.application.routes.draw do
  devise_for :users, :controllers => {  :omniauth_callbacks => "users/omniauth_callbacks"}
end
  • User has_many :team_users , has_many :teams, :through => :team_users

讲解细节

几个坑

  • 网上范例只给 identity.basic ,这是拿不到东西的。而且 slack 对拿 email 很严。搞了一晚上才确定 identity.email 才拿得到 email,非常蛋疼。
  • Rails 改版了,现在要从 request.env 才拿得到资料
  • slack 回传资料非常巢状,数错层就拉不到资料。有些资料要反覆调试 scope 才拿得到。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Writing Windows VxDs and Device Drivers, Second Edition

Writing Windows VxDs and Device Drivers, Second Edition

Karen Hazzah / CMP / 1996-01-12 / USD 54.95

Software developer and author Karen Hazzah expands her original treatise on device drivers in the second edition of "Writing Windows VxDs and Device Drivers." The book and companion disk include the a......一起来看看 《Writing Windows VxDs and Device Drivers, Second Edition》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具