Class: OmniAuth::Strategies::Zalo2

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/zalo2.rb

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



38
39
40
41
42
# File 'lib/omniauth/strategies/zalo2.rb', line 38

def authorize_params
  super.tap do |params|
    params[:app_id] = options[:client_id]
  end
end

#build_access_tokenObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/omniauth/strategies/zalo2.rb', line 48

def build_access_token
  # ref https://gitlab.com/oauth-xx/oauth2/-/blob/main/lib/oauth2/client.rb#L118
  response = client.request(
    client.options[:token_method],
    client.token_url,
    {
      headers: { "secret_key" => "#{options[:client_secret]}"},
      body: get_tokens_params,
      parse: :json
    }
  ).parsed

  # ref https://gitlab.com/oauth-xx/oauth2/-/blob/main/lib/oauth2/access_token.rb#L19
  ::OAuth2::AccessToken.from_hash(client, response)
end

#callback_urlObject



44
45
46
# File 'lib/omniauth/strategies/zalo2.rb', line 44

def callback_url
  options[:callback_url] || (full_host + script_name + callback_path)
end

#get_tokens_paramsObject



64
65
66
67
68
69
70
71
# File 'lib/omniauth/strategies/zalo2.rb', line 64

def get_tokens_params
  {}.tap do |params|
    params[:code]          = request.params['code']
    params[:app_id]        = options[:client_id]
    params[:grant_type]    = 'authorization_code'
    params[:code_verifier] = pkce_token_params[:code_verifier]
  end
end

#raw_infoObject



19
20
21
22
23
# File 'lib/omniauth/strategies/zalo2.rb', line 19

def raw_info
  @raw_info ||= access_token.get(
    "https://graph.zalo.me/v2.0/me?access_token=#{access_token.token}&fields=id,name,picture,phone"
  ).parsed || {}
end