snow · 2026.5.27 13:44 · 조회 1

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 dataJSON 형태의 추가 데이터
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: 클라이언트 자격증명으로 토큰 획득

1async function getManagementApiToken(): Promise<string> {2  const response = await fetch(3    'https://your-tenant-id.logto.app/oidc/token',4    {5      method: 'POST',6      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },7      body: new URLSearchParams({8        grant_type: 'client_credentials',9        client_id: process.env.LOGTO_M2M_APP_ID!,10        client_secret: process.env.LOGTO_M2M_APP_SECRET!,11        resource: 'https://your-tenant-id.logto.app/api',12        scope: 'all',13      }),14    }15  );16 17  const { access_token } = await response.json();18  return access_token;19}

사용자 목록 조회

1const token = await getManagementApiToken();2 3const users = await fetch(4  'https://your-tenant-id.logto.app/api/users?page=1&page_size=20',5  {6    headers: { Authorization: `Bearer ${token}` },7  }8).then(r => r.json());

사용자 생성

1const newUser = await fetch(2  'https://your-tenant-id.logto.app/api/users',3  {4    method: 'POST',5    headers: {6      Authorization: `Bearer ${token}`,7      'Content-Type': 'application/json',8    },9    body: JSON.stringify({10      primaryEmail: 'user@example.com',11      name: '홍길동',12      password: 'SecurePassword123!',13      customData: { department: 'engineering', employeeId: 'EMP-001' },14    }),15  }16).then(r => r.json());17 18console.log('생성된 사용자 ID:', newUser.id);

사용자 정보 수정

1await fetch(2  `https://your-tenant-id.logto.app/api/users/${userId}`,3  {4    method: 'PATCH',5    headers: {6      Authorization: `Bearer ${token}`,7      'Content-Type': 'application/json',8    },9    body: JSON.stringify({10      name: '김철수',11      customData: { plan: 'premium', updatedAt: new Date().toISOString() },12    }),13  }14);

사용자 삭제

1await fetch(2  `https://your-tenant-id.logto.app/api/users/${userId}`,3  {4    method: 'DELETE',5    headers: { Authorization: `Bearer ${token}` },6  }7);

사용자 검색

1const result = await fetch(2  'https://your-tenant-id.logto.app/api/users?search=user@example.com&searchFields[]=primaryEmail',3  {4    headers: { Authorization: `Bearer ${token}` },5  }6).then(r => r.json());

4.3 사용자 프로파일 관리

사용자 측에서 프로파일 수정

1import { useLogto } from '@logto/react';2 3function ProfileEditor() {4  const { updateProfile, fetchUserInfo } = useLogto();5 6  const handleNameUpdate = async (newName: string) => {7    await updateProfile({ name: newName });8    const updated = await fetchUserInfo();9    console.log('업데이트된 이름:', updated.name);10  };11 12  return (13    <form onSubmit={(e) => {14      e.preventDefault();15      handleNameUpdate(e.currentTarget.name.value);16    }}>17      <input name="name" placeholder="새 이름" />18      <button type="submit">저장</button>19    </form>20  );21}

비밀번호 재설정 (관리자)

1await fetch(2  `https://your-tenant-id.logto.app/api/users/${userId}/password`,3  {4    method: 'PATCH',5    headers: {6      Authorization: `Bearer ${token}`,7      'Content-Type': 'application/json',8    },9    body: JSON.stringify({ password: 'NewTemporaryPassword123!' }),10  }11);

4.4 Webhook으로 사용자 이벤트 처리

Webhook 설정

Admin Console → WebhooksCreate 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)

1import express from 'express';2import crypto from 'crypto';3 4const router = express.Router();5 6router.post('/webhooks/logto', express.raw({ type: 'application/json' }), (req, res) => {7  const signature = req.headers['logto-signature-sha-256'] as string;8  const secret = process.env.LOGTO_WEBHOOK_SECRET!;9  const expected = crypto10    .createHmac('sha256', secret)11    .update(req.body)12    .digest('hex');13 14  if (signature !== expected) {15    return res.status(401).json({ error: 'Invalid signature' });16  }17 18  const event = JSON.parse(req.body.toString());19 20  switch (event.event) {21    case 'User.Created':22      console.log('신규 사용자:', event.data.primaryEmail);23      break;24    case 'PostSignIn':25      console.log('로그인:', event.data.userId, event.sessionId);26      break;27  }28 29  res.status(200).json({ received: true });30});

다음 단계

사용자 관리를 익혔습니다. 이제 API 리소스 보호와 역할 기반 접근 제어(RBAC)를 설정할 차례입니다.

다음: Logto 인가(Authorization) 설정 — API Resources, RBAC, 토큰 검증


참고: Logto Management API — https://docs.logto.io/management-api

댓글

아직 댓글이 없습니다.

댓글을 작성하려면 로그인이 필요합니다.