> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # JSON 웹 토큰 그만큼`MastraJwtAuth`클래스는 JWT(JSON 웹 토큰)를 사용하여 Mastra에 대한 경량 인증 메커니즘을 제공합니다. 공유 비밀을 기반으로 들어오는 요청을 확인하고 다음을 사용하여 Mastra 서버와 통합합니다.`auth`옵션. ## 설치 사용하기 전에`MastraJwtAuth` class you have to install the `@mastra/auth` package. **npm**: ```bash npm install @mastra/auth@latest ``` **pnpm**: ```bash pnpm add @mastra/auth@latest ``` **Yarn**: ```bash yarn add @mastra/auth@latest ``` **Bun**: ```bash bun add @mastra/auth@latest ``` ## JWT 만들기 Mastra 서버에 대한 요청을 인증하려면 다음으로 서명된 유효한 JSON 웹 토큰(JWT)이 필요합니다.`MASTRA_JWT_SECRET`. 생성하는 가장 쉬운 방법은 다음을 사용하는 것입니다.[jwt.io](https://www.jwt.io/): 1. 선택하다**JWT Encoder**. 2. 아래로 스크롤하여**Sign JWT: Secret** section. 3. 비밀번호를 입력하세요(예:`supersecretdevkeythatishs256safe!`). 4. 딸깍 하는 소리**Generate example** to create a valid JWT. 5. 생성된 토큰을 복사하여 다음과 같이 설정합니다.`MASTRA_JWT_TOKEN` in your `.env` file. ## 사용예 생성된 JWT를 가져와 구성에 사용합니다.`MastraJwtAuth` in your Mastra server: ```typescript import { Mastra } from '@mastra/core' import { MastraJwtAuth } from '@mastra/auth' export const mastra = new Mastra({ server: { auth: new MastraJwtAuth({ secret: process.env.MASTRA_JWT_SECRET, }), }, }) ``` 방문하다[MastraJwtAuth](https://mastra.zisheng.pro/ko/reference/auth/jwt) for all available configuration options. 내부에[Studio](https://mastra.zisheng.pro/ko/docs/studio/overview), go to **Settings** and under **Headers** select the **"Add Header"** button. Enter `Authorization` as the header name and `Bearer ` as the value. ## 구성`MastraClient` 언제`auth` is enabled, all requests made with `MastraClient` must include a valid JWT in the `Authorization` header: ```typescript import { MastraClient } from '@mastra/client-js' export const mastraClient = new MastraClient({ baseUrl: 'https://', headers: { Authorization: `Bearer ${process.env.MASTRA_JWT_TOKEN}`, }, }) ``` 방문하다[Mastra Client SDK](https://mastra.zisheng.pro/ko/docs/server/mastra-client) for more configuration options. ### 인증된 요청 만들기 한 번`MastraClient` 가 구성되면 프런트엔드 애플리케이션에서 인증된 요청을 보내거나 다음을 사용할 수 있습니다: `curl` for quick local testing: **React**: ```tsx import { mastraClient } from '../../lib/mastra-client' export const TestAgent = () => { async function handleClick() { const agent = mastraClient.getAgent('weatherAgent') const response = await agent.generate('Weather in London') console.log(response) } return } ``` **cURL**: ```bash curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{ "messages": "Weather in London" }' ```