Class: OmniAuth::Strategies::TiktokBusinessOauth2
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::TiktokBusinessOauth2
- Defined in:
- lib/omniauth/strategies/tiktok_business_oauth2.rb
Constant Summary collapse
- USER_INFO_URL =
'https://business-api.tiktok.com/open_api/v1.3/business/get/'- USER_FIELDS =
'["username","display_name","profile_image","is_business_account"]'
Instance Method Summary collapse
- #access_token_info ⇒ Object
- #authorize_params ⇒ Object
-
#build_access_token ⇒ Object
It is necessary to override this method to avoid the "Content-Type" string getting turned into a symbol.
-
#callback_url ⇒ Object
Remove params as callback URL must match exactly the URL defined for the application.
- #raw_info ⇒ Object
- #tiktok_user_info ⇒ Object
- #token_params ⇒ Object
Instance Method Details
#access_token_info ⇒ Object
75 76 77 |
# File 'lib/omniauth/strategies/tiktok_business_oauth2.rb', line 75 def access_token_info access_token.to_hash.each_with_object({}) { |(key, value), hash| hash[key.to_s] = value } end |
#authorize_params ⇒ Object
15 16 17 18 19 |
# File 'lib/omniauth/strategies/tiktok_business_oauth2.rb', line 15 def super.tap do |params| params[:client_key] = .client_id end end |
#build_access_token ⇒ Object
It is necessary to override this method to avoid the "Content-Type" string getting turned into a symbol.
Unfortunately you can't just pass headers in token_params method because the original build_access_token deep symbolizes all parameters, and the OAuth2 gem expects the headers to be strings
81 82 83 84 |
# File 'lib/omniauth/strategies/tiktok_business_oauth2.rb', line 81 def build_access_token verifier = request.params["code"] client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params), deep_symbolize(.auth_token_params)) end |
#callback_url ⇒ Object
Remove params as callback URL must match exactly the URL defined for the application
42 43 44 |
# File 'lib/omniauth/strategies/tiktok_business_oauth2.rb', line 42 def callback_url super.split('?').first end |
#raw_info ⇒ Object
56 57 58 |
# File 'lib/omniauth/strategies/tiktok_business_oauth2.rb', line 56 def raw_info @raw_info ||= access_token_info.merge('user' => tiktok_user_info) end |
#tiktok_user_info ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/omniauth/strategies/tiktok_business_oauth2.rb', line 60 def tiktok_user_info @tiktok_user_info ||= begin headers = { 'Access-Token' => access_token.token } params = { business_id: access_token_info['open_id'], fields: USER_FIELDS } access_token.get(USER_INFO_URL, headers: headers, params: params, parse: :tiktok_business).parsed end end |
#token_params ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/omniauth/strategies/tiktok_business_oauth2.rb', line 46 def token_params .token_params.merge( headers: { 'Content-Type' => 'application/json' }, client_id: .client_id, client_secret: .client_secret, auth_code: request.params["code"], parse: :tiktok_business, ) end |