AccessToken 발급이 안됩니다

authorization_code, referrer 을 얻어와서 아래처럼 코드 작성하였는데, 에러 응답이 옵니다.
코드
import https from ‘https’;

import fs from ‘fs’;

import * as path from ‘path’;

// ----- 인증서/키 경로 (절대 경로 사용 권장) -----

const certPath = path.resolve(__dirname, ‘../../key/myple-mtls_public.crt’);

const keyPath = path.resolve(__dirname, ‘../../key/myple-mtls_private.key’);

const cert = fs.readFileSync(certPath);

const key = fs.readFileSync(keyPath);

export const requestTossAccessToken = (

authorizationCode: string,

referrer: string

) => {

const body = JSON.stringify({

“authorization_code”: authorizationCode,

“referrer”: referrer,

});

const options: https.RequestOptions = {

hostname: ‘apps-in-toss-api.toss.im’,

path: ‘/api-partner/v1/apps-in-toss/user/oauth2/generate-token’,

method: ‘POST’,

headers: {

‘Content-Type’: ‘application/json; charset=utf-8’,

‘Content-Length’: Buffer.byteLength(body),

    },

cert,

key,

rejectUnauthorized:true, // 서버의 인증서를 검증

};

const req = https.request(options, (res) => {

let data = ‘’;

res.on(‘data’, (chunk) => (data += chunk));

res.on(‘end’, () => {

console.log(‘Response:’, data);

    });

});

req.on(‘error’, (e) => {

console.error(‘Request error:’, e);

});

req.write(body);

req.end();

};

결과

Response: {“resultType”:“FAIL”,“error”:{“errorType”:0,“errorCode”:“40000”,“reason”:“Invalid request body”,“data”:{},“title”:null},“success”:null}

MTLS 설정하는겆 맞나요?

@dsdskm 님 안녕하세요

넵 해당 API는 server-to-server 통신으로 mTLS 인증서를 통한 통신이 필요합니다.

requestBody 확인을 부탁드립니다.

해결하였습니다.
제가 필드를 잘못쓰고 있었네요 감사합니다.

1개의 좋아요