Skip to content

Commit

Permalink
feat(connector): add kook connector
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-L committed Jul 11, 2024
1 parent ba415c9 commit 43a5ca1
Show file tree
Hide file tree
Showing 11 changed files with 674 additions and 0 deletions.
107 changes: 107 additions & 0 deletions packages/connectors/connector-kook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# KOOK connector

The official Logto connector for KOOK social sign-in web apps.

KOOK 应用社交登录官方 Logto 连接器 [中文文档](#kook-连接器)

**Table of contents**
- [KOOK connector](#kook-connector)
- [Get started](#get-started)
- [Create an Application in the KOOK Developer Center](#create-an-application-in-the-kook-developer-center)
- [Configure your KOOK connector](#configure-your-kook-connector)
- [Config types](#config-types)
- [Test KOOK connector](#test-kook-connector)
- [Reference](#reference)
- [KOOK 连接器](#kook-连接器)
- [配置你的 KOOK 连接器](#配置你的-kook-连接器)
- [配置类型](#配置类型)
- [测试 KOOK 连接器](#测试-kook-连接器)
- [参考](#参考)


## Get started

If you don't know the concept of the connector or don't know how to add this connector to your Sign-in experience, please see [Logto tutorial](https://docs.logto.io/docs/tutorials/get-started/enable-social-sign-in).

KOOK connector enables end-users to sign in to your application using their own KOOK account via KOOK OAuth 2.0 authentication protocol.

## Create an Application in the KOOK Developer Center

> 💡 **Tip**
> You can skip some sections if you have already finished.
> 💥 **Warning**
> You need to apply for KOOK OAuth2 permission before creating an OAuth2 Application. Please check out the information on the OAuth2 page or ask KOOK's staff in KOOK official developer server for more information.
>
> ![OAuth2 permission required page](/packages/connectors/connector-kook/docs/oauth2-permission-required-page.png)
1. Go to [KOOK Developer Center (KOOK 开发者中心)](https://developer.kookapp.cn/app/index) and sign in with your KOOK account. You may register a new account if you don't have one.
2. Click the **Create Application (新建应用)** button to create an application, choose a name for it (Ex: LogtoAuth) and click **Confirm (确定)**
3. Click the application icon you created, and go to **OAuth2** page.
4. Add the valid redirects (Ex: `${your_logto_origin}/callback/${connector_id}`) in the **Callback URIs (回调地址)** fields. You can find the redirect uri in the logto admin console connector details page.
5. Don't forget to check the **get_user_info** scope in the **OAuth2 link builder (OAuth2 链接生成器)**

![OAuth2 link builder (OAuth2 链接生成器)](/packages/connectors/connector-kook/docs/oauth2-link-builder.png)

## Configure your KOOK connector

Fill out the clientId and clientSecret field with Client ID and Client Secret you've got from OAuth2 page mentioned in the previous section.

### Config types

| Name | Type |
| ------------ | ------ |
| clientId | string |
| clientSecret | string |
| scope | string |

## Test KOOK connector

That's it. The KOOK connector should be available now. Don't forget to [Enable connector in sign-in experience](https://docs.logto.io/docs/recipes/configure-connectors/social-connector/enable-social-sign-in/).

## Reference

- [KOOK Developer Center - OAuth2](https://developer.kookapp.cn/doc/oauth2)

# KOOK 连接器

如果你还不知道连接器的概念,或者还不知道如何将本连接器添加至你的「登录体验」,请先参见 [Logto 教程](https://docs.logto.io/zh-cn/docs/tutorials/get-started/enable-social-sign-in)

> 💡 **Tip**
>
> 你可以跳过已经完成的部分。
> 💥 **Warning**
> 在创建 OAuth2 应用之前,你需要向 KOOK 申请 OAuth2 权限。如何申请请参考 OAuth2 页上的信息或在 KOOK 官方开发者服务器咨询 KOOK 工作人员。
>
> ![需要授权 OAuth2 权限](/packages/connectors/connector-kook/docs/oauth2-permission-required-page.png)
1. 打开 [KOOK 开发者中心](https://developer.kookapp.cn/app/index) 并登录你的 KOOK 最后。如果你没有注册账号,注册一个!
2. 点击 **新建应用** 按钮创建一个新的应用,然后给你的应用起一个名字(如:LogtoAuth)然后点击 **确定**
3. 点击你刚刚创建的应用的图标,切换到 **OAuth2** 页面。
4.**回调地址** 一栏填入你的 Callback URI(比如说:`${your_logto_origin}/callback/${connector_id}`)。你可以在 Logto 控制台的连接器详细页找到你的 Callback URI。
5. 不要忘记在 **OAuth2 链接生成器** 勾选 **get_user_info** scope。

![OAuth2 链接生成器](/packages/connectors/connector-kook/docs/oauth2-link-builder.png)

## 配置你的 KOOK 连接器

分别用 OAuth 应用详情页面中的 **Client ID****Client Secret** 字段填写 `clientId``clientSecret` 字段。

### 配置类型

| 名称 | 类型 |
| ------------ | ------ |
| clientId | string |
| clientSecret | string |
| scope | string |

## 测试 KOOK 连接器

大功告成。别忘了 [在登录体验中启用本连接器](https://docs.logto.io/docs/recipes/configure-connectors/social-connector/enable-social-sign-in/)

在 KOOK 连接器启用后,你可以构建并运行你的应用看看是否生效。

## 参考

- [KOOK 开发者中心 - OAuth2](https://developer.kookapp.cn/doc/oauth2)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions packages/connectors/connector-kook/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions packages/connectors/connector-kook/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@logto/connector-kook",
"version": "0.1.0",
"description": "KOOK connector implementation.",
"main": "./lib/index.js",
"module": "./lib/index.js",
"exports": "./lib/index.js",
"license": "MPL-2.0",
"type": "module",
"files": [
"lib",
"docs",
"logo.svg",
"logo-dark.svg"
],
"scripts": {
"precommit": "lint-staged",
"build:test": "rm -rf lib/ && tsc -p tsconfig.test.json --sourcemap",
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental",
"lint": "eslint --ext .ts src",
"lint:report": "pnpm lint --format json --output-file report.json",
"test": "vitest src",
"test:ci": "pnpm run test --silent --coverage",
"prepublishOnly": "pnpm build"
},
"engines": {
"node": "^20.9.0"
},
"eslintConfig": {
"extends": "@silverhand",
"settings": {
"import/core-modules": [
"@silverhand/essentials",
"got",
"nock",
"snakecase-keys",
"zod"
]
}
},
"prettier": "@silverhand/eslint-config/.prettierrc",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@silverhand/essentials": "^2.9.1",
"@logto/connector-kit": "workspace:^4.0.0",
"ky": "^1.2.3",
"zod": "^3.22.4"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@silverhand/eslint-config": "6.0.1",
"@silverhand/ts-config": "6.0.0",
"@types/node": "^20.11.20",
"@types/supertest": "^6.0.2",
"@vitest/coverage-v8": "^1.4.0",
"eslint": "^8.56.0",
"lint-staged": "^15.0.2",
"nock": "14.0.0-beta.7",
"prettier": "^3.0.0",
"rollup": "^4.12.0",
"rollup-plugin-output-size": "^1.3.0",
"supertest": "^7.0.0",
"typescript": "^5.3.3",
"vitest": "^1.4.0"
}
}
71 changes: 71 additions & 0 deletions packages/connectors/connector-kook/src/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type { ConnectorMetadata } from '@logto/connector-kit';
import { ConnectorConfigFormItemType, ConnectorPlatform } from '@logto/connector-kit';

/**
* Base authorization URL.
* https://developer.kookapp.cn/doc/oauth2
*/
export const authorizationEndpoint = 'https://www.kookapp.cn/app/oauth2/authorize';

/**
* Token endpoint.
* https://developer.kookapp.cn/doc/http/oauth#%E8%8E%B7%E5%8F%96AccessToken
*/
export const accessTokenEndpoint = 'https://www.kookapp.cn/api/oauth2/token';

/**
* User info endpoint.
* https://developer.kookapp.cn/doc/http/user#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF
*/

export const userInfoEndpoint = 'https://www.kookapp.cn/api/v3/user/me';

/**
* OAuth2 Scopes
* https://developer.kookapp.cn/doc/oauth2#%E7%9B%AE%E5%89%8D%E6%94%AF%E6%8C%81%E7%9A%84%20Scope%20%E5%8F%8A%E5%AF%B9%E5%BA%94%E8%83%BD%E5%8A%9B%E8%8C%83%E5%9B%B4
*/
export const scope = 'get_user_info';

export const defaultMetadata: ConnectorMetadata = {
id: 'kook-universal',
target: 'kook',
platform: ConnectorPlatform.Universal,
name: {
en: 'KOOK',
'zh-CN': 'KOOK',
},
logo: './logo.svg',
logoDark: null,
description: {
en: 'KOOK is a voice and text chat platform for gamers, which similar to Discord.',
'zh-CN': 'KOOK 是一个类似 Discord 的主要为游戏玩家设计的语音和文字聊天平台。',
},
readme: './README.md',
formItems: [
{
key: 'clientId',
type: ConnectorConfigFormItemType.Text,
required: true,
label: 'Client ID',
placeholder: '<client-id>',
},
{
key: 'clientSecret',
type: ConnectorConfigFormItemType.Text,
required: true,
label: 'Client Secret',
placeholder: '<client-secret>',
},
{
key: 'scope',
type: ConnectorConfigFormItemType.Text,
required: false,
label: 'Scope',
placeholder: '<scope>',
description:
"The `scope` determines permissions granted by the user's authorization. If you are not sure what to enter, do not worry, just leave it blank.",
},
],
};

export const defaultTimeout = 5000;
Loading

0 comments on commit 43a5ca1

Please sign in to comment.