lib/omniauth/strategies/zalo.rb in omniauth-zalo-0.1.4 vs lib/omniauth/strategies/zalo.rb in omniauth-zalo-0.1.5

- old
+ new

@@ -2,17 +2,22 @@ require 'json' module OmniAuth module Strategies class Zalo < OmniAuth::Strategies::OAuth2 + include BuildAccessToken + option :name, 'zalo' option :client_options, { site: 'https://oauth.zaloapp.com', - authorize_url: '/v3/auth', - token_url: '/v3/access_token', - token_method: :get, + authorize_url: '/v4/permission', + token_url: '/v4/access_token', + token_method: :post, + grant_type: 'authorization_code', + code_challenge: 'is5SvnFPQzBNP-nb-poEaFlsvK1a6S3NpVCz0vcHh0w', + code_verifier: 'h57bycdwryntewreomnbSyDrAG4kX7BeqS7g-luzvBE' } option :provider_ignores_state, true uid { raw_info['id'] } @@ -23,36 +28,28 @@ image: raw_info['picture']['data']['url'], } end def authorize_params - super.merge(app_id: self.options.client_id) + super.merge(app_id: self.options.client_id, code_challenge: options.client_options.code_challenge) end def build_access_token - token_url_params = {app_id: options.client_id, app_secret: options.client_secret, code: request.params['code'], redirect_uri: callback_url}.merge(token_params.to_hash(:symbolize_keys => true)) - parsed_response = client.request(options.client_options.token_method, client.token_url(token_url_params), parse: :json).parsed - hash = { - :access_token => parsed_response["access_token"], - :expires_in => parsed_response["expires_in"], - } - ::OAuth2::AccessToken.from_hash(client, hash) + oauth2_access_token end + def raw_info + get_user_info + end + alias :old_callback_url :callback_url def callback_url if request.params['callback_url'] request.params['callback_url'] else old_callback_url end - end - - def raw_info - @raw_info ||= JSON.load(access_token.get("https://graph.zalo.me/v2.0/me?access_token=#{access_token.token}&fields=id,birthday,name,gender,picture,phone").body) - rescue ::Errno::ETIMEDOUT - raise ::Timeout::Error end end end end