Wechat OAuth2 Strategy for OmniAuth 1.0.
Wechat OAuth2 Strategy for OmniAuth 1.0.
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"]
endYou 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"]:
…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"]
…No open issues yet, or sync has not completed.