# 4. 인증정보 조회 및 활용하기

{% hint style="warning" %}
**Deprecated**

이 문서는 더 이상 관리되지 않습니다.

[PortOne 개발자센터](https://developers.portone.io/)를 이용해주세요.
{% endhint %}

휴대폰 본인인증 완료이후 획득한 `imp_uid`를 이용하여 고객 인증정보를 조회할 수 있습니다.

### <mark style="color:blue;">**STEP 01.**</mark> 인증정보(imp\_uid) 서버단에서 획득하기

아래는 휴대폰 본인인증 앞단에서 넘어온 값을 서버단에서 수신받은 예제 입니다.

{% tabs %}
{% tab title="Node.js(팝업방식)" %}
{% code title="server-side" %}

```javascript
app.use(bodyParser.json());
  ...
  // "/certifications"에 대한 POST 요청을 처리하는 controller
  app.post("/certifications", async (request, response) => {
    // request의 body에서 imp_uid 추출
    const { imp_uid } = request.body; 
})
```

{% endcode %}
{% endtab %}

{% tab title="Node.js(리디렉션 방식)" %}
{% code title="server-side" %}

```javascript
app.use(bodyParser.json());
  ...
  // "/certifications/redirect"에 대한 GET 요청을 처리하는 controller
  app.get("/certifications/redirect", async (request, response) => {
    const { imp_uid } = request.query; // request의 query에서 imp_uid 추출
})
```

{% endcode %}
{% endtab %}
{% endtabs %}

### <mark style="color:blue;">**STEP 02.**</mark> 인증 정보 조회하기

포트원 서버에서 인증 정보를 조회하기 위해서 먼저 [**REST API access token**](https://portone.gitbook.io/docs/api/rest-api-access-token)을 발급받습니다. 발급받은 액세스 토큰(`access_token`)과 인증번호(`imp_uid`)로 <mark style="color:blue;">**본인인증 결과조회 REST API**</mark> 를 호출하여 인증 정보를 조회하는 예제입니다.

{% code title="server-side" %}

```javascript
app.use(bodyParser.json());
  ...
  // "/certifications"에 대한 POST 요청을 처리하는 controller
  app.post("/certifications", async (request, response) => {
    const { imp_uid } = request.body; // request의 body에서 imp_uid 추출
    try {
      // 인증 토큰 발급 받기
      const getToken = await axios({
        url: "https://api.iamport.kr/users/getToken",
        // POST method
        method: "post", 
        // "Content-Type": "application/json"
        headers: { "Content-Type": "application/json" }, 
        data: {
          imp_key: "imp_apikey", // REST API키
          imp_secret: "ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6bkA5lamv9OqDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f" // REST API Secret
        }
      });
      const { access_token } = getToken.data; // 인증 토큰
      ...
      // imp_uid로 인증 정보 조회
      const getCertifications = await axios({
        // imp_uid 전달
        url: \`https://api.iamport.kr/certifications/\${imp_uid}\`, 
        // GET method
        method: "get", 
        // 인증 토큰 Authorization header에 추가
        headers: { "Authorization": access_token } 
      });
      const certificationsInfo = getCertifications.data; // 조회한 인증 정보
      ...
    } catch(e) {
      console.error(e);
    }
  });
```

{% endcode %}

### <mark style="color:blue;">**STEP 03.**</mark> 인증 정보 활용하기

조회한 인증 정보에서 다음의 고객 정보를 추출하는 서비스 코드 예제입니다.

* `name`: 이름
* `gender`: 성별
* `birth`: 생년월일
* `unique_key`: CI 값과 동일. 온라인 주민번호와 같은 개인고유식별키
* `unique_in_site`: DI 값과 동일. 상점아이디(사이트)별로 할당되는 식별키

{% hint style="info" %}
위의 정보 외에 휴대폰 번호(**`phone`**) 및 통신사(**`carrier`**) 또는 외국인(**`foreigner`**) 여부는 **개인정보 제공동의 약관을 사이트에 게재**한 후 <mark style="color:red;">**<cs@portone.io>**</mark>**로 신청**하여 취득할 수 있습니다. 해당 부분은 당사 계약 이후 다날PG사로 요청 후 승인이 완료되면 이용 가능한 점 참고해 주시기 바랍니다.

**<메일 요청 신청 양식>**

* 상호명 :
* 사업자번호 :
* 본인인증용 다날 상점ID(CPID) :
* 업종 :
* 필요사유 :
* 개인정보취급방침 url : 앱서비스로 URL형태로 전달이 어려우신 경우 '개인정보취급방침' 경로를 캡쳐하여 전달주시기 바랍니다.

**<참고 - 포트원 이용 가맹점의 개인정보처리방침 적용 예시>**

* `(주)마플 : https://marpple.shop/kr/@/privacy`
* `(주)브레이브모바일 / 숨고 : https://soomgo.com/terms/privacy`
* `(주)마켓잇 : https://static.marketit.asia/static/privacy-terms.pdf`
  {% endhint %}

{% code title="Node.js" %}

```javascript
// "/certifications"에 대한 POST 요청을 처리하는 controller
  app.post("/certifications", async (request, response) => {
    const { imp_uid } = request.body; // request의 body에서 imp_uid 추출
    try {
      // 인증 토큰 발급 받기
      /* ...중략... */
      // imp_uid로 인증 정보 조회
      /* ...중략... */
      const certificationsInfo = getCertifications.data; // 조회한 인증 정보
      // unique_key: 개인식별 고유 키, unique_in_site: 사이트 별 개인식별 고유 키
      const { unique_key, unique_in_site, name, gender, birth } = certificationsInfo;
      ...
      // 연령 제한 로직
      if (new Date(birth).getFullYear() <= 1999) {
        // 연령 만족
      } else {
        // 연령 미달
      }
      ...
      // 1인 1계정 허용 로직
      // DB에서 unique_key 조회 후 가입여부 검사
      Users.find({ certificationKey: unique_key })
      .then((user) => {
        if (!user) {
          // 신규 고객
        } else {
          // 이미 가입된 고객
        }
      });
    } catch(e) {
      console.error(e);
    }
  });
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://portone.gitbook.io/docs/etc/phone/4..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
