Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to TikTok API v1.3 #10

Merged
merged 1 commit into from
Jan 12, 2023
Merged

Migrate to TikTok API v1.3 #10

merged 1 commit into from
Jan 12, 2023

Conversation

stenlarsson
Copy link
Collaborator

V1.2 of the TikTok Business API will be deprecated on Aug 15, 2023. See https://ads.tiktok.com/marketing_api/docs?id=1740579480076290.

It doesn't sound like any of the changes to the access token endpoint would affect this gem, but apparently it now becomes unhappy if you don't send the token request body as JSON.

Version 2.0.7 of the OAuth2 gem supports this if you set the "Content-Type" header to "application/json", see https://gitlab.com/oauth-xx/oauth2/-/issues/431.

Unfortunately you can't just pass headers in the token_params method because the build_access_token deep symbolizes all parameters, and the OAuth2 gem expects the headers to be strings. See https://github.com/omniauth/omniauth-oauth2/blob/3a43234ab5dd36a75f9c125c58fcfe1a37b26805/lib/omniauth/strategies/oauth2.rb#L126, and note that the token_params is a Hashie::Mash.

This means we have to override the build_access_token method to avoid the "Content-Type" string getting turned into a symbol.

Fixes #9.

V1.2 of the TikTok Business API will be deprecated on Aug 15, 2023. See https://ads.tiktok.com/marketing_api/docs?id=1740579480076290.

It doesn't sound like any of the changes to the access token endpoint would affect this gem, but apparently it now becomes unhappy if you don't send the token request body as JSON.

Version 2.0.7 of the OAuth2 gem supports this if you set the "Content-Type" header to "application/json", see https://gitlab.com/oauth-xx/oauth2/-/issues/431.

Unfortunately you can't just pass headers in `token_params` method because the `build_access_token` deep symbolizes all parameters, and the OAuth2 gem expects the headers to be strings. See https://github.com/omniauth/omniauth-oauth2/blob/3a43234ab5dd36a75f9c125c58fcfe1a37b26805/lib/omniauth/strategies/oauth2.rb#L126, and note that the `token_params` is a `Hashie::Mash`.

This means we have to override the `build_access_token` method to avoid the "Content-Type" string getting turned into a symbol.
@stenlarsson stenlarsson self-assigned this Jan 12, 2023
Copy link
Member

@kristofferek kristofferek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

It's a shame that we have to override the build_access_token method, but what else can we do.

gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.6'
gem.add_runtime_dependency 'oauth2', '~> 1.1'
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.8'
gem.add_runtime_dependency 'oauth2', '>= 2.0.7'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should lock this from version 3 as well? I guess omni-oauth2 already has that upper guard though.

Copy link
Collaborator Author

@stenlarsson stenlarsson Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we only indirectly depend on oauth2, so it is up to omni-oauth2 to restrict it properly. No need to restrict it more than necessary here.

@stenlarsson stenlarsson merged commit c6389ab into main Jan 12, 2023
@stenlarsson stenlarsson deleted the migrate-to-api-v1.3 branch January 12, 2023 09:07
stenlarsson added a commit that referenced this pull request Jan 12, 2023
Uses v1.3 of the TikTok Business API: #10
@stenlarsson stenlarsson mentioned this pull request Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Urgent] Tiktok v1.3 omniauth header error
2 participants