A drop-in replacement for KAS.
To add a service, use node scripts/add-service
which is an interactive CLI.
To remove a service, use DELETE FROM <table prefix>services WHERE name = '<service name>';
.
To modify a service, use UPDATE <table prefix>services SET <key> TO <value> WHERE name = '<service name>'
.
See sql/init.sql
for the database structure.
This documentation is generated partially by using the command:
node scripts/doc-responses
.
- RL: Requires Login (Cookies)
- RA: Rate limit
- RS: Requires Service (
Authorization: Bearer <token>
HTTP header) - NC: CSRF Token needed (See the CSRF section)
Request should be application/x-www-form-urlencoded
or application/json
and Content-Type
header should be set.
Returns JSON if not otherwise stated:
{"status":0,"message":"成功","result":"some result"}
-0
indicates OK{"status":1,"message":"非法请求","code":"EINVALID_REQUEST"}
-1
indicates an invalid request{"status":-1,"message":"TypeError: Cannot convert null or undefined to object","code":"EUNKNOWN"}
--1
indicates an unknown error{"status":-2,"message":"您尚未登录","code":"EUNAUTHORIZED"}
--2
indicates unauthorized{"status":429,"message":"您的操作过于频繁,请稍候再试。","code":"EABUSE"}
-429
indicates rate limit exceeded
Please use the code
to identify exceptions when possible, as status codes (except 0
) are non-informational and may subject to change.
Gets the status of the service.
{ status: 0 }
RL NC Multipart, Sets avatar
Form fields:
_csrf
frontend
=true
if is a frontend request (see below); else do not present this field (or leave blank)avatar:file
avatar file
Returns:
- Frontend request: redirect to home page (302) if success; else message as plain text
- Else: see below.
{ status: 0 }
{ status: 2, message: 'Not an image', code: 'ENOT_IMAGE' }
{ status: 3, message: 'Image too large', code: 'ETOO_LARGE' }
RL RA(1min), Sends verification email
Form fields:
email:string
email address
{ status: 0, message: '验证码已发送,请查收。' }
{ status: 2, message: '这个地址已经被其他帐号绑定。', code: 'ETAKEN' }
{ status: 3, message: '操作过于频繁,请过一分钟后再试', code: 'EABUSE' }
{ status: 4, message: '邮件地址不正确', code: 'EINVALID_ADDRESS' }
{ status: 5, message: '暂时无法发送邮件', code: 'ESEND' }
RL, Sets KEEER ID
Form fields:
id:string
KEEER ID
{ status: 0, message: '成功设置 KEEER ID' }
{ status: 3, message: 'KEEER ID 包含非法字符', code: 'EINVALID_ID' }
{ status: 4, message: '这个 KEEER ID 已被占用', code: 'EDUPLICATE' }
RL, Sets nickname
Form fields:
nickname:string
Nickname
{ status: 0, message: '成功修改昵称' }
{ status: 2, message: '昵称过长', code: 'ETOO_LONG' }
{ status: 3, message: '您不能使用这个昵称,确需使用请联系 KEEER', code: 'EINVALID_NICKNAME' }
Sets or finds back password
RL, Form fields:
current:string
Current passwordpassword:string
New password
Form fields:
number:string
Phone numbercode:string
Verification codepassword:string
New password
{ status: 0, message: '成功重置密码' }
{ status: 0, message: '成功修改密码' }
{ status: 2, message: '密码不符合要求', code: 'EINVALID_PASSWORD' }
{ status: 3, message: '验证码错误', code: 'EBAD_TOKEN' }
{ status: 4, message: '手机号不正确', code: 'EINVALID_PHONE_NUMBER' }
{ status: 5, message: '密码错误', code: 'EBAD_PASSWORD' }
RL, Sets phone number
Form fields:
number:string
Phone numbercode:string
Verification code
{ status: 0, message: '成功设置手机号' }
{ status: 2, message: '密码错误', code: 'EBAD_PASSWORD' }
{ status: 3, message: '验证码不正确', code: 'EBAD_TOKEN' }
{ status: 4, message: '手机号不正确', code: 'EINVALID_PHONE_NUMBER' }
RA(1min), Sends SMS.
Form fields:
number:string
Phone numbertype:enum
Send type
Types:
SMS_TYPE_REGISTER
RegisterSMS_TYPE_FIND_BACK_PASSWORD
Find back passwordSMS_TYPE_SET_PHONE_NUMBER
RL, Sets new phone number
{ status: 0, message: '验证码已发送,请查收。' }
{ status: 2, message: '您已经注册。', code: 'EDUPLICATE' }
{ status: 2, message: '您尚未注册。', code: 'ENOTFOUND' }
{ status: 3, message: '操作过于频繁,请过一分钟后再试', code: 'EABUSE' }
{ status: 4, message: '手机号不正确', code: 'EINVALID_PHONE_NUMBER' }
{ status: 5, message: '暂时无法发送短信', code: 'ESEND' }
RL, Gets user information
Returns:
avatar:string?
Avatar URLnickname:string?
NicknamekeeerId:string?
KEEER IDkredit:int
Centi-kredit
{ status: 0, result: { avatar, nickname, keeerId, kredit } }
RL, Gets current sessions Returns:
id:int
session IDcurrent:boolean
true if the session is the current sessionloginTime:string
ISO string of login timelastSeenTime:string
ISO string of last seen timeloginLocation:string
location of loginlastSeenLocation:string
location of last seenicons:string[]
icons names to show for the sessionuaString:string
name to show for the session
{ status: 0, result: [ (...) ] }
Gets login UI config for the designated service
Returns: { title, logoSrc, backgroundUrl, themeColor, redirectUrl, backgroundCopyright, backgroundCopyrightUrl }
{ status: 0, result: cfg }
{ status: 0, result: false }
: indicates no configuration in the service
RS, Gets KIUID of the token.
Returns :string
KIUID
{ status: 0, result: user.options.kiuid }
{ status: 2, message: '这个帐号不存在。', code: 'ENOTFOUND' }
RL, Gets [ and watches ] a recharge order
Returns :boolean
true if completed
{ status: 0, result: state }
{ status: 0, result: await createLongPoll(id) }
{ status: 2, message: '订单不存在', code: 'ENOTFOUND' }
{ status: 127, message: '超时', code: 'ETIMEOUT' }
RL, Creates recharge order
Form fields:
amount:number
Cents
{ status: 0, result: '/recharge-cashier?' + search }
RS, Makes payment
Form fields:
type:enum
Identity type, see belowidentity:string
Identityamount:number
Cents
Identity types:
phone-number
orphoneNumber
email
keeer-id
orkeeerId
kiuid
{ status: 0 }
{ status: 2, message: '找不到帐号', code: 'ENOTFOUND' }
{ status: 3, message: String(e), code: 'EINVALID_AMOUNT' }
Invalid amount{ status: 4, message: '余额不足', code: 'EINSUFFICIENT_KREDIT' }
User has insufficient kredit
Logs in (i.e. creates a token) [ and sets the token in response header ].
Headers:
Authorization: basic <credentials>
where credentials is base64(identity ':' password)
{ status: 0, message: '登录成功', result: token }
{ status: 2, message: '用户名或密码错误', code: 'EBAD_CREDENTIALS' }
Log out (i.e. destroys the token in URL or cookies) [ and removes cookies ]. Token is a KEEER Account Token (i.e. UUID for current implementation) or a session ID (i.e. integer).
For KEEER Account Tokens:
{ status: 0, message: '退出登录成功' }
{ status: 2, message: '已失效的登录', code: 'ENOTFOUND' }
For session IDs:
{ status: 0, message: '移除设备成功' }
{ status: 3, message: '不存在这个设备', code: 'ENOTFOUND' }
Signs up (i.e. creates a new user) [ and sets token cookie in response header ]
Form fields:
number:string
Phone numbercode:string
Verification codepassword:string
Password
{ status: 0, message: '您已经成功注册!', result: token }
{ status: 2, message: '密码不符合要求', code: 'EINVALID_PASSWORD' }
{ status: 3, message: '验证码错误', code: 'EBAD_TOKEN' }
{ status: 4, message: '手机号不正确', code: 'EINVALID_PHONE_NUMBER' }
{ status: 5, message: '您已经注册,请直接登录或找回密码', code: 'EDUPLICATE' }
See IDFrame.
Set a cookie named _csrf
with a random value, and submit this random value in a form field called _csrf
.
IDFrame is a functionality built into Node KAS that was previously available at https://idframe.keeer.net/js/appbar.js
. It allows KEEER services to show a box containing user information or log in links at the top-right of a page, in order to provide common look and feel for KAS. IDFrame can only be called with a *.keeer.net
referrer. Usage is shown below.
<div id="idframe"></div>
<style>#idframe { position: fixed; top: 12px; right: 12px; }</style>
<script src="https://account.keeer.net/api/idframe"></script>
<script>new idFrame.AppBarFrame({ container: '#idframe' })</script>
Class representing a IDFrame object.
Param | Type | Description |
---|---|---|
config.container |
string | HTMLElement |
IDFrame container, string will be interpreted as selector |
[config.loginUrl] |
string |
login button URL |
[config.signupUrl] |
string |
signup button URL |
[config.items[]] |
string | object |
items to show |
[config.serviceName] |
string |
KAS service name to include in login and sign up URLs |
Updates menu items.
Param | Type | Description |
---|---|---|
items[] |
string | object |
items to be displayed. |
# install dependencies
$ npm install
# initialize project
$ cp sample.env .env
$ vi .env # edit application config
$ node scripts/db-init # initialize database
# serve with hot reload at localhost:3000
$ npm run dev
# add a service
$ node scripts/add-service
# deploy assets to Aliyun OSS (optional)
$ node scripts/deploy-to-oss
# build for production and launch server
$ npm run build
$ npm run start
# update database schema
$ node scripts/migrate-database
Please do not run the content in sql/migration
directly. Instead, use the script at scripts/migrate-database
.
For detailed explanation on how things work, check out Nuxt.js docs.