🤹4. 인증정보 조회 및 활용하기
인증정보를 획득하고 활용하는 방법을 안내합니다.
STEP 01. 인증정보(imp_uid) 서버단에서 획득하기
app.use(bodyParser.json());
...
// "/certifications"에 대한 POST 요청을 처리하는 controller
app.post("/certifications", async (request, response) => {
// request의 body에서 imp_uid 추출
const { imp_uid } = request.body;
})app.use(bodyParser.json());
...
// "/certifications/redirect"에 대한 GET 요청을 처리하는 controller
app.get("/certifications/redirect", async (request, response) => {
const { imp_uid } = request.query; // request의 query에서 imp_uid 추출
})STEP 02. 인증 정보 조회하기
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);
}
});STEP 03. 인증 정보 활용하기
Last updated
Was this helpful?
