class OmniAuth::Dingtalk::Client::Base
Constants
- AUTHORIZE_URL
- GET_USER_ID_BY_UNIONID_URL
- GET_USER_INFO_BY_CODE_URL
- GET_USER_INFO_BY_ID_URL
Public Class Methods
new(client_id, client_secret, options = {}, &block)
click to toggle source
Calls superclass method
# File lib/omniauth-dingtalk/client/base.rb, line 21 def initialize(client_id, client_secret, options = {}, &block) opts = { authorize_url: AUTHORIZE_URL.fetch(options[:authorize_method].to_s, AUTHORIZE_URL['qrcode']), token_url: token_url, token_method: :get }.merge(options) super(client_id, client_secret, opts, &block) end
Public Instance Methods
get_token(params, access_token_opts = {}, extract_access_token = options[:extract_access_token])
click to toggle source
Calls superclass method
# File lib/omniauth-dingtalk/client/base.rb, line 72 def get_token(params, access_token_opts = {}, extract_access_token = options[:extract_access_token]) super(token_params.merge(params), access_token_opts, extract_access_token) end
get_user_id_by_unionid(access_token, unionid)
click to toggle source
# File lib/omniauth-dingtalk/client/base.rb, line 44 def get_user_id_by_unionid(access_token, unionid) request(:post, GET_USER_ID_BY_UNIONID_URL, headers: { 'Content-Type' => 'application/json' }, body: { unionid: unionid }.to_json, params: { access_token: access_token } ).parsed end
get_user_info(params = {})
click to toggle source
# File lib/omniauth-dingtalk/client/base.rb, line 60 def get_user_info(params = {}) raise NotImplementedError end
get_user_info_by_code(code)
click to toggle source
# File lib/omniauth-dingtalk/client/base.rb, line 31 def get_user_info_by_code(code) t = (Time.now.to_f * 1000).to_i.to_s raw_sign = Base64.encode64(OpenSSL::HMAC.digest('SHA256', secret, t)).strip sign = CGI.escape(raw_sign) url = "#{GET_USER_INFO_BY_CODE_URL}?accessKey=#{id}×tamp=#{t}&signature=#{sign}" request(:post, url, headers: { 'Content-Type' => 'application/json' }, body: { tmp_auth_code: code }.to_json ).parsed end
get_user_info_by_id(access_token, id)
click to toggle source
# File lib/omniauth-dingtalk/client/base.rb, line 52 def get_user_info_by_id(access_token, id) request(:post, GET_USER_INFO_BY_ID_URL, headers: { 'Content-Type' => 'application/json' }, body: { userid: id }.to_json, params: { access_token: access_token } ).parsed end
token_params()
click to toggle source
# File lib/omniauth-dingtalk/client/base.rb, line 68 def token_params { appid: id, appsecret: secret } end
token_url()
click to toggle source
# File lib/omniauth-dingtalk/client/base.rb, line 64 def token_url self.class.const_get(:TOKEN_URL) rescue nil end