Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

omniauth-wechat-oauth2

> 编程语言
Open source

Wechat OAuth2 Strategy for OmniAuth 1.0.

273 stars0 likes2 views
WebsiteGitHub

About

Wechat OAuth2 Strategy for OmniAuth 1.0.

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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

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