
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
omniauth-wechat-oauth2
Advanced tools
Wechat OAuth2 Strategy for OmniAuth 1.0.
You need to get a wechat API key at: https://mp.weixin.qq.com
Add to your Gemfile
:
gem "omniauth-wechat-oauth2"
Then bundle install
.
Here's an example for adding the middleware to a Rails app in config/initializers/omniauth.rb
:
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
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.
config.omniauth :wechat, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"],
:authorize_params => {:scope => "snsapi_base"}
Here's an example of an authentication hash available in the callback by accessing request.env["omniauth.auth"]
:
{
:provider => "wechat",
:uid => "123456789",
:info => {
nickname: "Nickname",
sex: 1,
province: "Changning",
city: "Shanghai",
country: "China",
headimgurl: "http://image_url",
unionid: 'unionid'
},
:credentials => {
:token => "token",
:refresh_token => "another_token",
:expires_at => 7200,
:expires => true
},
:extra => {
:raw_info => {
openid: "openid"
nickname: "Nickname",
sex: 1,
province: "Changning",
city: "Shanghai",
country: "China",
headimgurl: "http://image_url",
unionid: 'unionid'
}
}
}
Wechat Qiey usage and configuration are the same with normal account above.
config.omniauth :wechat_qiye, ENV["WECHAT_APP_ID"], ENV["WECHAT_APP_SECRET"],
:authorize_params => {:scope => "snsapi_base"}
Auth hash request.env["omniauth.auth"]
{
:provider => "wechat_qiye",
:uid => "123456789",
:info => {
userid: "userid",
name: "name",
department: [2],
gender: "1",
weixinid: "weixinid",
avatar: "avatar",
status: 1,
extattr: {"foo" => "bar"}
},
:credentials => {
:token => "token",
:refresh_token => "another_token",
:expires_at => 7200,
:expires => true
},
:extra => {
:raw_info => {
userid: "userid",
name: "name",
department: [2],
gender: "1",
weixinid: "weixinid",
avatar: "avatar",
status: 1,
extattr: {"foo" => "bar"}}
}
}
}
FAQs
Unknown package
We found that omniauth-wechat-oauth2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.