snow · 2026.5.28 03:31 · 조회 2
Logto 사용자 관리
사용자관리LogtoIAMManagement API
Logto의 사용자 관리 기능은 Admin Console(GUI)과 Management API(프로그래밍 방식) 두 가지 방법으로 이용할 수 있습니다.
4.1 Admin Console로 사용자 관리
사용자 목록 조회
Admin Console → Users 메뉴에서 모든 사용자를 확인할 수 있습니다.
제공 기능:
- 이메일, 이름, 사용자 ID로 검색
- 가입일, 마지막 로그인 시간 확인
- 사용자 상태 (활성/차단) 변경
- 사용자 삭제
사용자 상세 정보
사용자를 클릭하면 다음 정보를 확인하고 수정할 수 있습니다.
| 섹션 | 내용 |
|---|---|
| Basic info | 이름, 아바타, 사용자 이름 |
| Contact info | 이메일, 전화번호 (인증 여부 포함) |
| Social accounts | 연결된 소셜 계정 목록 |
| Roles | 할당된 역할(Role) |
| Organizations | 소속 조직 목록 |
| Custom data | JSON 형태의 추가 데이터 |
| MFA | 등록된 MFA 팩터 |
수동 사용자 생성
Admin Console에서 직접 사용자를 생성할 수 있습니다 (초대 기반 서비스에 유용).
Admin Console → Users → Create user
→ Email 또는 Phone number 입력
→ 임시 비밀번호 설정 (또는 이메일로 초대 발송)
사용자 일시정지 (Suspend)
악성 사용자 또는 탈퇴 처리 없이 접근을 차단할 때 사용합니다.
사용자 상세 → Danger zone → Suspend user
→ 해당 사용자는 로그인 시 "계정이 정지됨" 오류 표시
4.2 Management API로 사용자 관리
Management API는 서버 코드에서 사용자를 프로그래밍 방식으로 관리할 수 있는 REST API입니다.
M2M 앱 생성 및 토큰 획득
Management API 호출 전, Machine-to-Machine 타입 앱을 생성하고 접근 토큰을 발급받아야 합니다.
Step 1: M2M 앱 생성
Admin Console → Applications → Create application → Machine to Machine
→ App 이름 입력 → Roles에서 "Logto Management API" 선택
Step 2: 클라이언트 자격증명으로 토큰 획득
async function getManagementApiToken(): Promise<string> {
const response = await fetch(
'https://your-tenant-id.logto.app/oidc/token',
{
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: process.env.LOGTO_M2M_APP_ID!,
client_secret: process.env.LOGTO_M2M_APP_SECRET!,
resource: 'https://your-tenant-id.logto.app/api',
scope: 'all',
}),
}
);
const { access_token } = await response.json();
return access_token;
}
사용자 목록 조회
const token = await getManagementApiToken();
const users = await fetch(
'https://your-tenant-id.logto.app/api/users?page=1&page_size=20',
{
headers: { Authorization: `Bearer ${token}` },
}
).then(r => r.json());
사용자 생성
const newUser = await fetch(
'https://your-tenant-id.logto.app/api/users',
{
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
primaryEmail: 'user@example.com',
name: '홍길동',
password: 'SecurePassword123!',
customData: { department: 'engineering', employeeId: 'EMP-001' },
}),
}
).then(r => r.json());
console.log('생성된 사용자 ID:', newUser.id);
사용자 정보 수정
await fetch(
`https://your-tenant-id.logto.app/api/users/${userId}`,
{
method: 'PATCH',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: '김철수',
customData: { plan: 'premium', updatedAt: new Date().toISOString() },
}),
}
);
사용자 삭제
await fetch(
`https://your-tenant-id.logto.app/api/users/${userId}`,
{
method: 'DELETE',
headers: { Authorization: `Bearer ${token}` },
}
);
사용자 검색
const result = await fetch(
'https://your-tenant-id.logto.app/api/users?search=user@example.com&searchFields[]=primaryEmail',
{
headers: { Authorization: `Bearer ${token}` },
}
).then(r => r.json());
4.3 사용자 프로파일 관리
사용자 측에서 프로파일 수정
import { useLogto } from '@logto/react';
function ProfileEditor() {
const { updateProfile, fetchUserInfo } = useLogto();
const handleNameUpdate = async (newName: string) => {
await updateProfile({ name: newName });
const updated = await fetchUserInfo();
console.log('업데이트된 이름:', updated.name);
};
return (
<form onSubmit={(e) => {
e.preventDefault();
handleNameUpdate(e.currentTarget.name.value);
}}>
<input name="name" placeholder="새 이름" />
<button type="submit">저장</button>
</form>
);
}
비밀번호 재설정 (관리자)
await fetch(
`https://your-tenant-id.logto.app/api/users/${userId}/password`,
{
method: 'PATCH',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ password: 'NewTemporaryPassword123!' }),
}
);
4.4 Webhook으로 사용자 이벤트 처리
Webhook 설정
Admin Console → Webhooks → Create webhook
이름: User Lifecycle Events
Endpoint URL: https://api.yourapp.com/webhooks/logto
이벤트 선택:
✓ User.Created
✓ User.Deleted
✓ User.Data.Updated
✓ PostSignIn
✓ PostRegister
Webhook 수신 서버 예시 (Node.js/Express)
import express from 'express';
import crypto from 'crypto';
const router = express.Router();
router.post('/webhooks/logto', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['logto-signature-sha-256'] as string;
const secret = process.env.LOGTO_WEBHOOK_SECRET!;
const expected = crypto
.createHmac('sha256', secret)
.update(req.body)
.digest('hex');
if (signature !== expected) {
return res.status(401).json({ error: 'Invalid signature' });
}
const event = JSON.parse(req.body.toString());
switch (event.event) {
case 'User.Created':
console.log('신규 사용자:', event.data.primaryEmail);
break;
case 'PostSignIn':
console.log('로그인:', event.data.userId, event.sessionId);
break;
}
res.status(200).json({ received: true });
});
다음 단계
사용자 관리를 익혔습니다. 이제 API 리소스 보호와 역할 기반 접근 제어(RBAC)를 설정할 차례입니다.
다음: Logto 인가(Authorization) 설정 — API Resources, RBAC, 토큰 검증
참고: Logto Management API — https://docs.logto.io/management-api
댓글
아직 댓글이 없습니다.
댓글을 작성하려면 로그인이 필요합니다.