百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

omniauth-wechat-oauth2

> 编程语言
开源

OmniAuth 1.0 版的 Wechat OAuth2 策略

273 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

OmniAuth 1.0 版的 Wechat OAuth2 策略

Omniauth-wechat-oauth2

Wechat OAuth2 Strategy for OmniAuth 1.0.

You need to get a wechat API key at: https://mp.weixin.qq.com

  • Wechat oauth2 specification can be found at: https://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
  • Wechat Qiye oauth2 specification can be found at: http://qydev.weixin.qq.com/wiki/index.php?title=OAuth验证接口

Installation

Add to your Gemfile:

ruby
gem "omniauth-wechat-oauth2"

Then bundle install.

Usage

Here's an example for adding the middleware to a Rails app in config/initializers/omniauth.rb:

ruby
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :wechat, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"]
end

You can now access the OmniAuth Wechat OAuth2 URL: /auth/wechat

Configuration

You can configure several options, which you pass in to the provider method via a hash:

  • scope: Default is "snsapi_userinfo". It can either be snsapi_base or snsapi_userinfo. When scope is "snsapi_userinfo", after wechat user is authenticated, app can query userinfo using the acquired access_token.

For devise user, you can set up scope in your devise.rb as following.

ruby
config.omniauth :wechat, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"],
    :authorize_params => {:scope => "snsapi_base"}

Auth Hash

Here's an example of an authentication hash available in the callback by accessing request.env["omniauth.auth"]:

…

Wechat Qiye OAuth2

Wechat Qiey usage and configuration are the same with normal account above.

ruby
config.omniauth :wechat_qiye, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"],
    :authorize_params => {:scope => "snsapi_base"}

Auth hash request.env["omniauth.auth"]

…

Issues· 7 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言