NURI SHOPPING ADMIN

HOW IT WORKS

이 데모 사이트는 이렇게 연결됐습니다

아래 Node.js 코드는 현재 실행 중인 데모 소스에서 직접 읽어 표시합니다.

  1. 포털에서 준비

    사이트를 등록해 live client와 secret을 한 번 발급하고, callback URL과 origin을 정확히 등록합니다. 그 다음 고객사 사용자 ID와 전화번호를 동기화합니다.

  2. 서버에서 거래 생성

    비밀번호 확인 뒤 고객사 서버가 client secret으로 거래를 생성합니다. Drop-in은 UI token을 화면에 전달하고, Hosted는 반환된 hosted_url로 이동합니다.

    async function createMfaTransaction(nuriAuth, req, user, flow) {
      const nonce = crypto.randomBytes(32).toString('base64url');
      const state = crypto.randomBytes(32).toString('base64url');
      req.session.mfaPending = { userId: user.id, nonce, state, flow, createdAt: Date.now() };
      return nuriAuth.createTransaction({ externalUserId: user.id, firstFactorRef: req.sessionID, browserNonce: nonce, endUserIp: req.ip, idempotencyKey: crypto.randomUUID(), hosted: flow === 'hosted', redirectUri: flow === 'hosted' ? config.hostedRedirectUri : undefined, state: flow === 'hosted' ? state : undefined });
    }
  3. Drop-in 화면 코드

    SDK script, 컴포넌트 속성, verified 이벤트 처리는 실제 화면 코드와 같습니다.

    function dropinPage(tx, csrf) {
      const sdk = `<script src="${escapeHtml(config.sdkUrl)}"></script>`;
      return page('Drop-in 전화 인증', `<section class="narrow"><p class="eyebrow">DROP-IN</p><h1>전화 2차 인증</h1><p class="lead">이 화면 안에 &lt;nuriauth-mfa&gt; 웹 컴포넌트를 붙였습니다.</p><nuriauth-mfa id="demo-mfa" transaction-id="${escapeHtml(tx.transaction_id)}" ui-token="${escapeHtml(tx.ui_token)}" api-base="${escapeHtml(config.publicApiBase)}" css-url="https://call.nuri.you/mfa-sdk/v1/nuriauth-mfa.css" lang="ko"></nuriauth-mfa><form id="dropin-complete" action="/login/mfa" method="post"><input type="hidden" name="csrf" value="${escapeHtml(csrf)}"><input type="hidden" name="proof" value=""></form></section>`, { script: `${sdk}<script type="module" src="/static/dropin.js"></script>` });
    }
    const component = document.querySelector('#demo-mfa');
    const completion = document.querySelector('#dropin-complete');
    component.addEventListener('nuriauth:verified', async event => {
      completion.elements.proof.value = event.detail.proof;
      const response = await fetch(completion.action, {
        method: 'POST', headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ proof: completion.elements.proof.value, csrf: completion.elements.csrf.value })
      });
      const result = await response.json();
      if (result.ok) location.assign(result.redirect);
    });
  4. 서버에서 최종 검증

    Drop-in proof 또는 Hosted code는 반드시 고객사 서버에서 한 번 소비한 뒤에만 로그인 세션을 재생성합니다.

    async function finishDropin(nuriAuth, pending, proof) { return nuriAuth.introspect({ proof, browserNonce: pending.nonce, externalUserId: pending.userId }); }
    async function finishHosted(nuriAuth, pending, code, state) { if (!timingSafeEqual(state, pending.state)) return { active: false }; return nuriAuth.exchangeHostedCode({ code, redirectUri: config.hostedRedirectUri }); }

언어와 무관한 HTTP 예시

curl -u "$CLIENT_ID:$CLIENT_SECRET" \
  -H 'Content-Type: application/json' \
  -d '{"external_user_id":"shopping-admin","purpose":"login","first_factor_ref":"password-session","browser_nonce":"random","idempotency_key":"uuid","hosted":true,"redirect_uri":"https://calldemo.nuri.you/auth/hosted/callback","state":"random-state"}' \
  https://call.nuri.you/mfa-api/v1/web/transactions

curl -u "$CLIENT_ID:$CLIENT_SECRET" \
  -H 'Content-Type: application/json' \
  -d '{"code":"one-time-code","redirect_uri":"https://calldemo.nuri.you/auth/hosted/callback"}' \
  https://call.nuri.you/mfa-api/v1/web/hosted/token

보안 체크리스트