关于sso:你可能想要集成一个-Discourse-论坛使用-Authing-SSO-零代码帮你实现单点登录

18次阅读

共计 7093 个字符,预计需要花费 18 分钟才能阅读完成。

Authing 是什么?

Authing 是国内首款以开发者为核心的全场景身份云产品,集成了所有支流身份认证协定,为企业和开发者提供欠缺平安的用户认证和拜访治理服务。

以「API First」作为产品基石,把身份畛域所有罕用性能都进行了模块化的封装,通过全场景编程语言 SDK 将所有能力 API 化提供给开发者。同时,用户能够灵便的应用 Authing 凋谢的 RESTful APIs 进行性能拓展,满足不同企业不同业务场景下的身份治理需要。

传统零碎 SSO 单点登录革新

首先,须要对原有零碎的用户体系进行革新,使其可能适应通用的用户认证标准协议(如 OAuth)。如果零碎体量较大,甚至还须要思考将原有业务中的用户体系抽出,专门做成单点登录的用户核心。须要进行设计、编码、测试、降级、扩容等一系列简单的开发运维操作,才可能实现。

该形式耗时间,耗精力,耗老本,危险大(须要在业务畛域之外一直去踩坑)。

Authing SSO 集成

如果您的利用是基于 Authing 提供的身份零碎进行开发,那么祝贺你,能够应用较少的代码(或者配置)即可轻松几步,疾速实现单点登录的集成。

该形式低成本,毋庸额定设计和开发,采纳标准协议,轻松买通。

Discourse 装置

参考资料:

  • Discourse 官网 Docker 仓库:https://github.com/discourse/…
  • 装置指南文档:https://github.com/discourse/…

倡议将 Discourse Docker 仓库 Fork,并在本地先进行开发调试确认无误后再进行产品环境的装置。上面是简略的装置步骤阐明及配置中常见问题的 FAQ。

留神:请在 Linux 服务器或者 macOS 下进行装置(Windows 须要自行摸索一下)。

拉取 Discourse Docker 仓库

git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse

应用自动化配置脚本:

./discourse-setup

root 用户的话,须要在后面加 sudo 运行。依据提醒一步一步输出配置项,实现装置配置。默认的配置在本地运行的时候大概率会运行不起来。

关上 containers/app.yml 配置文件进行配置调整,如果手动配置,也能够执行:

cp samples/standalone.yml containers/app.yml

复制一个示例模板作为开始。

利用配置

在开始配置之前,先确保域名曾经绑定到服务器上(DNS 中的 A 记录绑定),或者本地批改 /etc/hosts 文件(不要应用 example.com 或者须要强制 https 的域名后缀作为本地开发调试,如:.app.dev 等)。

环境变量设置参考:

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8
  EMBER_CLI_PROD_ASSETS: 1
  # DISCOURSE_DEFAULT_LOCALE: en

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  #UNICORN_WORKERS: 3

  ## TODO: The domain name this Discourse instance will respond to
  ## Required. Discourse will not work with a bare IP number.
  DISCOURSE_HOSTNAME: 'discourse.local'

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  # DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'willin@willin.org'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  DISCOURSE_SMTP_ADDRESS: smtp.mail.qq.com
  DISCOURSE_SMTP_PORT: 25
  DISCOURSE_SMTP_USER_NAME: willin@willin.org
  DISCOURSE_SMTP_PASSWORD: "password"
  DISCOURSE_SMTP_ENABLE_START_TLS: fales       # (optional, default true)
  DISCOURSE_SMTP_AUTHENTICATION: plain
  DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none

  DISCOURSE_NOTIFICATION_EMAIL: willin@willin.org

  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  #LETSENCRYPT_ACCOUNT_EMAIL: me@example.com
  ## The http or https CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details
  #DISCOURSE_CDN_URL: https://discourse-cdn.example.com
  ## The maxmind geolocation IP address key for IP address lookup
  ## see https://meta.discourse.org/t/-/137387/23 for details
  #DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456

简略阐明:

  • UNICORN_WORKERS:依据 CPU 数量决定 Worker 数量或者手动配置
  • DISCOURSE_HOSTNAME:正确配置域名
  • DISCOURSE_SMTP_XXX:正确配置 SMTP 邮件发送服务,不然会收不到验证码和告诉邮件

插件配置:

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-oauth2-basic.git
          - git clone https://github.com/angelim/discourse_user_auto_activation.git

这三个插件的作用:

  • Docker 治理,自带默认
  • OAuth 2 集成,用于与 Authing SSO 连贯实现单点登录
  • 主动激活(邮箱)插件,可选

启动论坛服务

揭示:先配置好 SSL 证书再启动服务(参考 FAQ SSL 证书配置,或者应用 Let’s Encrypt 签发证书)。

配置实现后制作镜像:

./launcher bootstrap app
./launcher start app

如果曾经初始化过,能够通过从新制作镜像的形式:

./launcher rebuild app

过程漫长,急躁期待。上面整顿了我在调试过程中遇到的一些问题和一些提醒。

FAQ

域名配置

次要批改模板:

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
  - "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"
  • 如果须要 SSL 反对,"templates/web.ssl.template.yml" 这个模板文件须要引入。
  • 如果须要收费的域名证书更新,"templates/web.letsencrypt.ssl.template.yml" 这个模板须要引入。

同时依据须要,将端口凋谢进去:

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "80:80"   # http
  - "443:443" # https

SSL 证书配置

首先确认一下文件目录的映射是否正确:

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/log/var-log
      guest: /var/log

相似这样的目录映射,将证书文件搁置到对应的 ssl 目录下,查看这两个文件门路是否正确:

/var/discourse/shared/standalone/ssl/ssl.crt
/var/discourse/shared/standalone/ssl/ssl.key

自签证书参考:

openssl genrsa -aes256 -passout pass:gsahdg -out ssl.pass.key 4096
openssl rsa -passin pass:gsahdg -in ssl.pass.key -out ssl.key  
openssl req -new -key ssl.key -out ssl.csr             

# You are about to be asked to enter information that will be incorporated
# into your certificate request.
# What you are about to enter is what is called a Distinguished Name or a DN.
# There are quite a few fields but you can leave some blank
# For some fields there will be a default value,
# If you enter '.', the field will be left blank.
# -----
# Country Name (2 letter code) []:CN
# State or Province Name (full name) []:Jiangsu
# Locality Name (eg, city) []:Nanjing
# Organization Name (eg, company) []:Xibang Tech
# Organizational Unit Name (eg, section) []:
# Common Name (eg, fully qualified host name) []:discourse.local
# Email Address []:willin@willin.org

# Please enter the following 'extra' attributes
# to be sent with your certificate request
# A challenge password []:      
openssl x509 -req -sha256 -days 365 -in ssl.csr -signkey ssl.key -out ssl.crt

自签证书须要信赖,在 macOS 下就是双击关上 .crt 文件,抉择信赖始终信赖,过程中须要输出两次明码即可。

禁用 SSL

该步骤并非必要,如果懒得配置 SSL 本地自签名证书(比方我),能够将原有的配置考出,把 SSL 局部给正文掉。

# 先将配置从镜像拷贝进去
docker cp app:/etc/nginx/conf.d/discourse.conf ./discourse.conf
# 批改配置后执行
docker cp ./discourse.conf app:/etc/nginx/conf.d/discourse.conf 
docker exec app nginx -s reload

其中次要批改的局部为,将 https 申请跳回 http:

# attempt to preserve the proto, must be in http context
map $http_x_forwarded_proto $thescheme {
  default $scheme;
  https http;
}

将 80 跳转到 443 的逻辑删除:

server {
  listen 80;
  # 将跳转的局部删除,并与 listen 443 的 `server` 合并
}

Build 或启动失败

失败起因:执行 git clone 命令之后出错,该状况呈现在国内服务器拉取镜像。能够在码云或者其余国内 Git 服务商上导入 Github 的仓库,而后用国内镜像地址。

失败起因:域名无法访问,查看配置或本地 HOSTS,是否曾经绑定好域名。

失败起因:启动胜利但无法访问,个别仅在本地调试时呈现,域名尽管是能够随便起,但要留神规定(比方没有配置 SSL 证书 nginx-error 日志会有,比方 .dev 域名我在本地测试时应用自签 SSL 证书就始终无法访问但 nginx-access 日志却显示失常)。

拜访论坛并进行初始化配置

拜访 localhost 或者你配置的域名,注册管理员用户并进行初始化配置。

通过邮件验证链接从新进入后,开始初始化配置。11 个步骤设置完后,进入治理后盾 - 设置。

左侧边栏抉择【登录】

敞开本地登录(倡议稳当起见,在单点登录配置实现后敞开也能够)。

进入插件设置:

点击设置后停留在以后配置页面(稍后持续设置)。在新窗口中关上 Authing 控制台。

Authing SSO 单点登录集成

在单点登录 SSO 利用市场中搜寻 Discourse。点击获取利用进入配置。

第一步是填写论坛名称,第二步进行登录配置。

只须要填入一个 Redirect URI(留神一下这里是辨别 http / https 的,如果不对就会报 redirect_uri_mismatch 谬误),其余配置项对应复制填入到 Discourse 插件配置中。示例:http://discourse.local/auth/oauth2_basic/callback(替换你的域名,后边门路保持一致)。

另外还须要配置的我的项目为:

  • oauth2 json user id path:填入 sub
  • oauth2 json username path:填入 nickname 或者 username
  • oauth2 json name path:填入 name
  • oauth2 json email path:填入 email
  • oauth2 json email verified path:填入 email_verified
  • oauth2 json avatar path:填入 picture
  • oauth2 send auth header 在 HTTP 受权标头中发送客户端凭据 :勾销勾选

保留插件配置。

保留拜访受权之后,能够在新的隐衷窗口测试一下。

主动将 Authing 用户信息带入论坛。测试胜利。

同时管理员账户(邮箱与 Authing 用户雷同)即可无缝连接至 Authing SSO 单点登录形式。

至此实现,功败垂成。

延长

通过 Authing SSO 还能够通过无代码的形式接入:

  • 协同工具:如禅道、ProcessOn、石墨文档、Notion、Tower、Teambition、飞书、Confluence 等
  • 云计算资源:如阿里云、腾讯云、AWS、百度智能云、金山云、华为云等
  • 开发者工具:如 Gitlab、Jira、Coding.net、Bitbucket、Jenkins 等
  • (目前利用商店里提供)其余共计 120 种服务 / 平台 / 软件

同时还能够以低代码 / 零代码的模式,接入各类零碎、软件,目前反对的自建利用反对的协定有:

  • OAuth 2.0
  • SAML 2
  • CAS

应用 Authing SSO,能够轻松集成 NodeBB 论坛、Wordpress 站点等等等等……的单点登录。

正文完
 0