From 771c84b7d5931a1fe3d5e285aca998b5bdce183e Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 29 Jan 2023 01:21:59 +0000 Subject: [PATCH 1/7] add tiktok provider --- packages/core/src/providers/tiktok.js | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/core/src/providers/tiktok.js diff --git a/packages/core/src/providers/tiktok.js b/packages/core/src/providers/tiktok.js new file mode 100644 index 0000000000..aa40dd0353 --- /dev/null +++ b/packages/core/src/providers/tiktok.js @@ -0,0 +1,36 @@ +/** @type {import(".").OAuthProvider} */ +export default function TikTok(options) { + return { + id: "tiktok", + name: "TikTok", + type: "oauth", + version: "2.0", + authorization: { + url: "https://www.tiktok.com/auth/authorize/", + params: { + scope: "user.info.basic", + response_type: "code", + client_key: process.env.TIKTOK_CLIENT_KEY, + redirect_uri: options.redirect_uri, + }, + }, + token: { + url: "https://open-api.tiktok.com/oauth/access_token/", + params: { + client_key: process.env.TIKTOK_CLIENT_KEY, + client_secret: process.env.TIKTOK_CLIENT_SECRET, + grant_type: "authorization_code", + }, + }, + userinfo: "https://open-api.tiktok.com/user/info/", + profile(profile) { + return { + id: profile.open_id, + name: profile.display_name, + image: profile.avatar_url + }; + }, + checks: ["state"], + options + } +} From 22c6cc952c85b0408f85a60e5b4e39758b86895a Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 29 Jan 2023 01:36:47 +0000 Subject: [PATCH 2/7] replace envvars with options ref --- packages/core/src/providers/tiktok.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/providers/tiktok.js b/packages/core/src/providers/tiktok.js index aa40dd0353..2a3d8e4354 100644 --- a/packages/core/src/providers/tiktok.js +++ b/packages/core/src/providers/tiktok.js @@ -10,15 +10,15 @@ export default function TikTok(options) { params: { scope: "user.info.basic", response_type: "code", - client_key: process.env.TIKTOK_CLIENT_KEY, + client_key: options.clientId, redirect_uri: options.redirect_uri, }, }, token: { url: "https://open-api.tiktok.com/oauth/access_token/", params: { - client_key: process.env.TIKTOK_CLIENT_KEY, - client_secret: process.env.TIKTOK_CLIENT_SECRET, + client_key: options.clientId, + client_secret: options.clientSecret, grant_type: "authorization_code", }, }, From f0b5ce051424a0e6c888c7f9d2a56718651bbe0d Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 29 Jan 2023 01:36:51 +0000 Subject: [PATCH 3/7] docs --- .../reference/05-oauth-providers/tiktok.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/docs/reference/05-oauth-providers/tiktok.md diff --git a/docs/docs/reference/05-oauth-providers/tiktok.md b/docs/docs/reference/05-oauth-providers/tiktok.md new file mode 100644 index 0000000000..0c12842945 --- /dev/null +++ b/docs/docs/reference/05-oauth-providers/tiktok.md @@ -0,0 +1,39 @@ +--- +id: tiktok +title: TikTok +--- + +## Documentation + +https://developers.tiktok.com/doc/login-kit-web/ + +## Configuration + +https://developers.tiktok.com/doc/getting-started-create-an-app/ + +## Options + +The **TikTok Provider** comes with a set of default options: + +- [TikTok Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/tiktok.js) + +You can override any of the options to suit your own use case. + +:::note +TikTok requires that a `redirect_uri` param is sent. This must be configured to use the full URL, including protocol, domain, port and path to your Sign In API (default path for Auth.js is `api/auth/signin`). It should look something like `https://mydomain.com/api/auth/signin`. +::: + +## Example + +```js +import TikTokProvider from "next-auth/providers/tiktok"; +... +providers: [ + TikTokProvider({ + clientId: process.env.TIKTOK_CLIENT_KEY, + clientSecret: process.env.TIKTOK_CLIENT_SECRET + redirect_uri: "https://mydomain.com/api/auth/signin" + }) +] +... +``` From 637b8992ae509080efb1068d2f1ece5fd21429ae Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 29 Jan 2023 01:41:22 +0000 Subject: [PATCH 4/7] add tiktok oauth-type --- packages/core/src/providers/oauth-types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/providers/oauth-types.ts b/packages/core/src/providers/oauth-types.ts index 66c75b2fc8..c7237556d4 100644 --- a/packages/core/src/providers/oauth-types.ts +++ b/packages/core/src/providers/oauth-types.ts @@ -54,6 +54,7 @@ export type OAuthProviderType = | "slack" | "spotify" | "strava" + | "tiktok" | "todoist" | "trakt" | "twitch" From b2fabbd8e06f0ac17e50027d899051b4f44c41c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Sun, 29 Jan 2023 13:27:13 +0000 Subject: [PATCH 5/7] Apply suggestions from code review --- packages/core/src/providers/tiktok.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/core/src/providers/tiktok.js b/packages/core/src/providers/tiktok.js index 2a3d8e4354..a9f062f000 100644 --- a/packages/core/src/providers/tiktok.js +++ b/packages/core/src/providers/tiktok.js @@ -6,20 +6,17 @@ export default function TikTok(options) { type: "oauth", version: "2.0", authorization: { - url: "https://www.tiktok.com/auth/authorize/", + url: "https://www.tiktok.com/auth/authorize", params: { scope: "user.info.basic", - response_type: "code", client_key: options.clientId, - redirect_uri: options.redirect_uri, }, }, token: { - url: "https://open-api.tiktok.com/oauth/access_token/", + url: "https://open-api.tiktok.com/oauth/access_token", params: { client_key: options.clientId, client_secret: options.clientSecret, - grant_type: "authorization_code", }, }, userinfo: "https://open-api.tiktok.com/user/info/", @@ -30,7 +27,6 @@ export default function TikTok(options) { image: profile.avatar_url }; }, - checks: ["state"], options } } From a81d9de15ee8254d6ffd4efeca9622d65b111035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Sun, 29 Jan 2023 13:33:56 +0000 Subject: [PATCH 6/7] Update oauth-types.ts --- packages/core/src/providers/oauth-types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/providers/oauth-types.ts b/packages/core/src/providers/oauth-types.ts index c7237556d4..66c75b2fc8 100644 --- a/packages/core/src/providers/oauth-types.ts +++ b/packages/core/src/providers/oauth-types.ts @@ -54,7 +54,6 @@ export type OAuthProviderType = | "slack" | "spotify" | "strava" - | "tiktok" | "todoist" | "trakt" | "twitch" From 59866245fdda2b08a72704c442eb0a4dc364cafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Sun, 29 Jan 2023 13:34:44 +0000 Subject: [PATCH 7/7] Apply suggestions from code review --- packages/core/src/providers/tiktok.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/providers/tiktok.js b/packages/core/src/providers/tiktok.js index a9f062f000..21a983e54a 100644 --- a/packages/core/src/providers/tiktok.js +++ b/packages/core/src/providers/tiktok.js @@ -19,7 +19,7 @@ export default function TikTok(options) { client_secret: options.clientSecret, }, }, - userinfo: "https://open-api.tiktok.com/user/info/", + userinfo: "https://open-api.tiktok.com/user/info", profile(profile) { return { id: profile.open_id,