현재 내 애플리케이션 플랫폼에 도메인은 http://localhost:3000 로 설정했고
Redirect URI 은 http://localhost:3000/v1/auth/login/kakao 로 설정한 상태입니다.
아래 api로 인가코드을 요청하고
https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=REST_API_KEY&redirect_uri=http://localhost:3000/v1/auth/login/kakao
{“statusCode”:404,“message”:“Cannot GET /v1/auth/login/kakao?code=85_FNEKucS6N23ooxDAFGqurVasceBtj4RXVKQhzO7r6I7pYT64NpNbTES7F05g1QnQ9Jgo9dBEAAAF8_qhTBQ”,“error”:“Not Found”}
이런 응답을 받았습니다.
이 후에 code 값 85_FNEKucS6N23ooxDAFGqurVasceBtj4RXVKQhzO7r6I7pYT64NpNbTES7F05g1QnQ9Jgo9dBEAAAF8_qhTBQ 를
아래 함수에 넣어 토큰을 요청하는데
도저히 되질 않네요…ㅠ 계속 401에러가 나고…
async getKakaoToken(code:string) {
return await axios({
method: 'POST',
url: 'https://kauth.kakao.com/oauth/token',
headers : {
'Content-type' : 'application/x-www-form-urlencoded;charset=utf-8'
},
data: {
grant_type : "authorization_code",
client_id :REST_API_KEY,
redirect_uri : "http://localhost:3000/v1/auth/login/kakao",
code : code
}
});
}
위의 함수처럼 해보기도 하고
아래처럼 form 데이터로 한번 더 바꿔서 data를 전송하면
async getKakaoToken(code:string) {
const makeFormData = params => {
const searchParams = new URLSearchParams()
Object.keys(params).forEach(key => {
searchParams.append(key, params[key])
})
return searchParams
}
return await axios({
method: 'POST',
url: 'https://kauth.kakao.com/oauth/token',
headers : {
'Content-type' : 'application/x-www-form-urlencoded;charset=utf-8'
},
data: makeFormData({
grant_type : "authorization_code",
client_id : REST_API_KEY,
redirect_uri : "http://localhost:3000/v1/auth/login/kakao",
code : code
})
});
}
[Nest] 10620 - 2021. 11. 08. 오후 4:56:52 ERROR [ExceptionsHandler] Converting circular structure to JSON
→ starting at object with constructor ‘ClientRequest’
| property ‘socket’ → object with constructor ‘TLSSocket’
— property ‘_httpMessage’ closes the circle
TypeError: Converting circular structure to JSON
→ starting at object with constructor ‘ClientRequest’
| property ‘socket’ → object with constructor ‘TLSSocket’
— property ‘_httpMessage’ closes the circle
at JSON.stringify ()
at stringify (C:\Users\dexign\Desktop\jebs-api\node_modules\express\lib\response.js:1123:12)
at ServerResponse.json (C:\Users\dexign\Desktop\jebs-api\node_modules\express\lib\response.js:260:14)
at ExpressAdapter.reply (C:\Users\dexign\Desktop\jebs-api\node_modules@nestjs\platform-express\adapters\express-adapter.js:32:57)
at RouterResponseController.apply (C:\Users\dexign\Desktop\jebs-api\node_modules@nestjs\core\router\router-response-controller.js:14:36)
at C:\Users\dexign\Desktop\jebs-api\node_modules@nestjs\core\router\router-execution-context.js:175:48
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at C:\Users\dexign\Desktop\jebs-api\node_modules@nestjs\core\router\router-execution-context.js:47:13
at C:\Users\dexign\Desktop\jebs-api\node_modules@nestjs\core\router\router-proxy.js:9:17
이런 에러가 납니다…
제 앱id는 661116 입니다