Skip to content

Commit

Permalink
Merge pull request #137 from snow/master
Browse files Browse the repository at this point in the history
FIX: consider '' in params as equal with nil, in ControllerApi#wechat_public_oauth2
  • Loading branch information
Eric-Guo authored Jul 27, 2016
2 parents 151a4d5 + 9edac30 commit cf5aa8f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/wechat/controller_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def wechat_oauth2(scope = 'snsapi_base', page_url = nil, &block)
def wechat_public_oauth2(oauth2_url)
if cookies.signed_or_encrypted[:we_openid].blank? && params[:code].blank?
redirect_to oauth2_url
elsif cookies.signed_or_encrypted[:we_openid].blank? && params[:code].present? && params[:state] == wechat.jsapi_ticket.oauth2_state
elsif cookies.signed_or_encrypted[:we_openid].blank? &&
params[:code].present? &&
params[:state].to_s == wechat.jsapi_ticket.oauth2_state.to_s # params[:state] maybe nil and wechat.jsapi_ticket.oauth2_state may be nil
access_info = wechat.web_access_token(params[:code])
cookies.signed_or_encrypted[:we_openid] = { value: access_info['openid'], expires: self.class.oauth2_cookie_duration.from_now }
yield access_info['openid'], access_info
Expand Down

0 comments on commit cf5aa8f

Please sign in to comment.