SnowPass

Java Client Library

RP 백엔드용 private API 클라이언트 — snowpass-client-java

com.snowoncard.snowpass:snowpass-client-java 는 SnowPass private API (/v1) 를 래핑한 경량 클라이언트다. 의존성은 Jackson 뿐이며 Spring 이 필요 없다 (Java 17+).

Installation

<dependency>
  <groupId>com.snowoncard.snowpass</groupId>
  <artifactId>snowpass-client-java</artifactId>
  <version>0.1.0</version>
</dependency>

Initialization

SnowPassClient client = SnowPassClient.builder()
    .baseUrl("http://localhost:8080")          // 운영: 내부망 SnowPass 서버 주소
    .apiSecret(System.getenv("SNOWPASS_API_SECRET")) // sk_* — 서버에만 보관
    .connectTimeout(Duration.ofSeconds(5))
    .build();

apiSecret 은 서버 전용이다. 브라우저·모바일 앱·로그에 노출하면 안 된다.

User Lifecycle

// 사용자 보장 (idempotent upsert) — externalUserId 는 RP 가 생성한 System User ID (UUID)
EnsureUserResponse user = client.ensureUser(systemUserId, displayName, loginId, email);

// MFA 상태 조회
UserStatus status = client.getUser(systemUserId);
if (!status.hasPasskey()) {
    // 등록 흐름으로 분기
}

// 회원 탈퇴 연동 (credential 연쇄 삭제)
client.deleteUser(systemUserId);

Ceremony Tokens (등록·인증 토큰)

// 등록 토큰 (300초 1회용) — 페이지에 내려 JS SDK 에 전달
RegisterTokenResponse reg = client.createRegisterToken(systemUserId, FactorType.PASSKEY);

// 인증 토큰 (180초 1회용) — 미등록이면 FACTOR_NOT_ENROLLED 예외
AuthTokenResponse auth = client.createAuthToken(systemUserId, FactorType.TOTP);

Result Token Verification (결과 토큰 검증)

브라우저 SDK 가 돌려준 result token 은 반드시 백엔드에서 검증한다 (jti 1회용 보장).

VerifyResult result = client.verifyResultToken(resultToken);
if (result.valid() && systemUserId.equals(result.sub())) {
    // 세션을 AUTHENTICATED 로 승격
}

Credential Management

CredentialList creds = client.listCredentials(systemUserId);
client.renameCredential(systemUserId, credentialId, "회사 노트북");
client.deleteCredential(systemUserId, credentialId, /* force */ false); // 마지막이면 LAST_CREDENTIAL 409
client.deleteTotp(systemUserId, false);

Recovery & Helpdesk

// recovery code 10개 재발급 — 평문은 이 응답에서만
RecoveryCodesResponse codes = client.generateRecoveryCodes(systemUserId);

// recovery code 로그인 (1회용 소모) → result token 반환
String resultToken = client.verifyRecoveryCode(systemUserId, code);

// 헬프데스크: bypass code 발급 (기본 15분 TTL) / 검증
BypassCodeResponse bypass = client.createBypassCode(systemUserId, 15);
String token = client.verifyBypassCode(systemUserId, code);

// MFA 초기화 — 전체 credential·recovery 폐기 + 잠금 해제
client.resetMfa(systemUserId);

Error Handling

API 오류는 SnowPassApiException 으로 던져지며 서버의 error.code (USER_LOCKED, FACTOR_NOT_ENROLLED, LAST_CREDENTIAL 등) 와 HTTP status 를 담는다. 전체 코드 목록은 Error Codes 참고.

On this page