【中文版】README.zh-CN.md
This repository contains two example projects demonstrating how to use Coze's Realtime API and OAuth authentication:
- realtime-quickstart-react: A React-based real-time voice conversation example
- quickstart-oauth-server: OAuth authentication server example
This is a real-time voice conversation application example built using React and Coze Realtime API.
- Real-time voice conversation
- Text message display support
- Microphone control
- Video functionality support (optional)
- Multiple authentication methods support (PAT, Device, JWT, PKCE, Web OAuth)
- Install dependencies:
npm run run-preinstall
npm install
- Start the development server:
npm start
- Visit
http://localhost:3000
in your browser
Main configuration items are in src/App.tsx
:
botId
: Your Coze Bot ID- Authentication method: Choose by commenting/uncommenting the corresponding
useToken
hook
const { getToken } = useTokenWithPat();
// const { getToken } = useTokenWithDevice();
// const { getToken } = useTokenWithJWT();
// const { getToken } = useTokenWithPKCE();
// const { getToken } = useTokenWithWeb();
- Modify
src/hooks/use-token-with-pat.ts
to return your access token
const useTokenWithPat = () => {
const getToken = () =>
'Your access token';
return {
getToken,
};
};
## quickstart-oauth-server
This is an OAuth authentication server example supporting various OAuth authentication flows.
### Supported Authentication Methods
- Device OAuth
- JWT OAuth
- PKCE OAuth
- Web OAuth
### Quick Start
1. Install dependencies:
```bash
rush update
- Configure authentication information: Modify the corresponding configuration file based on your authentication method:
src/device-oauth/coze_oauth_config.json
src/jwt-oauth/coze_oauth_config.json
src/pkce-oauth/coze_oauth_config.json
src/web-oauth/coze_oauth_config.json
- Start the corresponding authentication server:
# Device OAuth server
npm run start-device # port 3002
# JWT OAuth server
npm run start-jwt # port 3001
# PKCE OAuth server
npm run start-pkce # port 3003
# Web OAuth server
npm run start-web # port 3004
GET /get_device_code
: Get device codePOST /get_device_token
: Get device tokenPOST /refresh_device_token
: Refresh token
GET /get_jwt_token
: Get JWT token
GET /pkce_login
: Get PKCE authentication URLPOST /get_pkce_token
: Get PKCE tokenPOST /refresh_pkce_token
: Refresh token
GET /web_login
: Get Web authentication URLPOST /get_web_token
: Get Web tokenPOST /refresh_web_token
: Refresh token
- Node.js 16+
- npm 7+
- Modern browser (with WebRTC support)
ISC License
- Ensure proper management of keys and authentication information in production environments
- Recommended to add necessary security measures in production environments
- Example code is for reference only and should be adjusted according to specific requirements