Class: OmniAuth::Strategies::TiktokOauth2

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

Constant Summary collapse

USER_INFO_URL =
'https://business-api.tiktok.com/open_api/v1.3/user/info/'

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



20
21
22
23
24
# File 'lib/omniauth/strategies/tiktok_oauth2.rb', line 20

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

#build_access_tokenObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/omniauth/strategies/tiktok_oauth2.rb', line 67

def build_access_token
  client.auth_code.get_token(
    request.params['code'],
    {
      redirect_uri: callback_url,
      headers: {'Content-Type' => 'application/json'},
    }.merge(token_params.to_hash(symbolize_keys: true)),
    deep_symbolize(options.auth_token_params)
  )
end

#callback_urlObject

Remove params as callback URL must match exactly the URL defined for the application



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

def callback_url
  super.split('?').first
end

#headersObject



61
62
63
64
65
# File 'lib/omniauth/strategies/tiktok_oauth2.rb', line 61

def headers
  {
    'Access-Token' => access_token.token,
  }
end

#raw_infoObject



57
58
59
# File 'lib/omniauth/strategies/tiktok_oauth2.rb', line 57

def raw_info
  @raw_info ||= access_token.get(USER_INFO_URL, headers: headers, parse: :tiktok).parsed
end

#token_paramsObject



48
49
50
51
52
53
54
55
# File 'lib/omniauth/strategies/tiktok_oauth2.rb', line 48

def token_params
  options.token_params.merge(
    app_id: options.client_id,
    secret: options.client_secret,
    auth_code: request.params["auth_code"],
    parse: :tiktok,
  )
end