TikTok Provider usage for Sandbox Environment #11946
Unanswered
DevinLeamy
asked this question in
Help
Replies: 1 comment
-
Hey @DevinLeamy , they already merge a fix of this issue #12168 , but it is not on a release yet, if you still need the Tiktok Provider on your application, you can set it up as a custom provider const CustomTiktok: OAuth2Config<any> & Provider =
{
async [customFetch](...args) {
const url = new URL(args[0] instanceof Request ? args[0].url : args[0])
if (url.pathname.endsWith("/token/")) {
const [url, request] = args
const customHeaders = {
...request?.headers,
"content-type": "application/x-www-form-urlencoded",
}
const customBody = new URLSearchParams(request?.body as string)
customBody.append("client_key", process.env.AUTH_TIKTOK_ID!)
const response = await fetch(url, {
...request,
headers: customHeaders,
body: customBody.toString(),
})
const json = await response.json()
return Response.json({ ...json })
}
return fetch(...args)
},
id: "tiktok",
name: "TikTok",
type: "oauth",
client: {
token_endpoint_auth_method: "client_secret_post",
},
authorization: {
url: "https://www.tiktok.com/v2/auth/authorize",
params: {
client_key: process.env.AUTH_TIKTOK_ID,
scope: "user.info.profile",
},
},
token: "https://open.tiktokapis.com/v2/oauth/token/",
userinfo:
"https://open.tiktokapis.com/v2/user/info/?fields=open_id,avatar_url,display_name,username",
profile(profile) {
return {
id: profile.data.user.open_id,
name: profile.data.user.display_name,
image: profile.data.user.avatar_url,
email: profile.data.user.email || profile.data.user.username || null,
}
},
} and then add it to your list of providers export const { handlers, auth } = NextAuth({ providers: [ GitHub, CustomTiktok ] }) Please do let me know if this workaround works for you or if you have any questions :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. I'm setting up TikTok authentication in my application using the TikTok provider.
My application has not been approved by TikTok, so I'm using TikTok's Sandbox environment.
I've setup a callback URL
https://mydomain.com/api/auth/callback/tiktok/
, scopes, and a test user.The TikTok provider failed to work. After the user approves the requested scopes, there's a server-side error:
(though an auth code is returned)
The PR introducing the TikTok provider #8131 says
Which would suggest that it's not applicable to my use case. That said, I've seen no indication from the TikTok documentation that it should not work. Wondering if anyone else encountered this failure while using the TikTok provider in development?
Beta Was this translation helpful? Give feedback.
All reactions