req.get('origin')이 undefined인 경우에는 어떻게 해야하나요?
localhost:8003은 문제없이 동작하나
localhost:8003/mypost 같은 url을 사용해보려하니
api측에서 req.get('origin')을 못하고있습니다.
post를 보낼때는 또 추가로 보내야하는게 있다고하는데,
어떻게 해야할까요?
이한솔
0
1
질문있습니다
https://www.inflearn.com/questions/12695
여기 질문 내용과 중복되어서 링크도 함께 남깁니다.
답변해주신 2번 내용에서 프론트 요청인지, 서버요청 인지에 따라 분기처리해주는게 좋다고 하셨는데, 마지막 대댓글처럼 main.pug에서 ajax요청시에는 프론트요청이고, call서버의 index.js에서 axios요청시에는 서버 요청인건 알겠는데... 이걸 어떻게 구분해서 처리하는건지 잘 모르겠습니다 ㅠㅠ
둘 다 값이 clientSecret에 담겨오는 것 같은데 ... 이 값이 어느 요청인지 구분하는 방법이 무엇인가요?
혹시 req.headers부분으로 구분하는건가요??
nodeMoon
0
1
질문이여
질문
url.parse가 정확히 무슨 역할을하는지 모르겟네요.
밑에 보시는바와 같이, localhost:8003에서 localhost:8002로 요청보낼때, 인데요.
console.log(req.get('origin'))
이런식으로 로그 찍어보면, 이런 값이 나오는데
http://localhost:8003
url.parse를 하면, 모든 값이 나오는데,
왜그런건가요 ?? ??
console.log(url.parse(req.get('origin')))
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'localhost:8003',
port: '8003',
hostname: 'localhost',
hash: null,
search: null,
query: null,
pathname: '/',
path: '/',
href: 'http://localhost:8003/'
}
hsjo12
0
1
질문이요.
현재 두개의 시크릿키 client 와 frontSecret 키들이 있잖아요.
1.
clinentSecret 키는 서버간의 인증을 위한 키
frontSecret키는 프론트에서 서버로 보내줄때 인증을 위한키
보안상의 이유로 클라이언트 키가 프론트에서 보이는 것 보다
프론트 키가 프론트에서 보이는 걸 선호하는 이유가, 프론트키 와 유저가 직접입력한 도메인을 알아야 기에 좀 더 안전해서 프론트 키를 쓴다.
지금 제가 이해 한게 맞나요?
2.
현재 프론트에서 보내는 프론트 키 + 도메인으로 토큰을 발급 받을때요.
localhost:8003/ 을 입렵하면,
라우터 / 이거 에서 frontSecret 키를 main.pug 로보내고,
main.pug는 다시 locallhost:8002/v2/token 으로 보낸후,
이 라우터 안에서
DB에 제대로 유저가 등록한 도메인으로 요청을 했는지,
where: { host: url.parse(req.get('origin')).host } 로
DB 체크후 CORS로 넘겨진후..
/token 라우터로 가서, 보내준 frontKey가 맞는지 체크하고
토큰을 발급을 해주잖아요.
그래서 /token 라우터 코드를
const { frontSecret } = req.body; 프론트키받고
where: { frontSecret } 이런식으로 DB에서 체크후
DB에 프론트키가 있는지 여부를 보고, 토큰을 발행해주나요.
그렇다면, 이전에 clientSeceret 키로 주고 받았잔아요.
예를 들면, nodebird-call 을 보시면,
request 함수에,
const URL = 'http://localhost:8002/v2';
const request = async (req, api) => {
try {
if (!req.session.jwt) {
const tokenResult = await axios.post(`${URL}/token`, {
clientSecret: process.env.CLIENT_SECRET,
});
.......}
이런식으로 axios를 통해서 http://localhost:8002/v2/token 에다가, clientSecret을
보내고, 위와 같은 흐름으로 client 키를 통해서
v2.js 에서 도메인도 체크하고난후,
/token 라우터를 통해서,
const { frontSecret } = req.body; 프론트키받고
where: { frontSecret } 이런식으로 DB에서 체크후
체크를 하는데 , 문제는 frontSecret을 받으려고하잖아요.
이럴경우는 clientSecret을 따로 받을 수 있게,
v2-1.js 이런식으로 새로 만들고,
아예 http://localhost:8002/v2-1/token 이런식으로 요청을 받을수 있게 하는게 나은가요 ??
3. 그리고, 만약에 clientSecret만 으로 토큰을
받는다면, 도메인 체크는 할 필요가 없어지는게 맞죠?
애초에 프론트에 나오지 않아 해킹에 위험이 적어지니까요.
hsjo12
0
3
스스로 해보기3(클라이언트/서버 비밀키 구분하기) 에러가 나서 문의 남깁니다.
터미널에서는 아래처럼 오류가 납니다.sequelize deprecated Model.find has been deprecated, please use Model.findOne instead node_modules/sequelize/lib/model.js:4212:9Executing (default): SELECT `id`, `host`, `type`, `clientSecret`, `frontSecret`, `createdAt`, `updatedAt`, `deletedAt`, `userId` FROM `domains` AS `domain` WHERE ((`domain`.`deletedAt` > '2019-02-24 14:06:19' OR `domain`.`deletedAt` IS NULL) AND `domain`.`host` = 'localhost:8003') LIMIT 1;OPTIONS /v2/token 204 31.393 ms - 0Executing (default): SELECT `id`, `host`, `type`, `clientSecret`, `frontSecret`, `createdAt`, `updatedAt`, `deletedAt`, `userId` FROM `domains` AS `domain` WHERE ((`domain`.`deletedAt` > '2019-02-24 14:06:19' OR `domain`.`deletedAt` IS NULL) AND `domain`.`host` = 'localhost:8003') LIMIT 1;Executing (default): SELECT `id`, `host`, `type`, `clientSecret`, `frontSecret`, `createdAt`, `updatedAt`, `deletedAt`, `userId` FROM `domains` AS `domain` WHERE ((`domain`.`deletedAt` > '2019-02-24 14:06:19' OR `domain`.`deletedAt` IS NULL) AND `domain`.`host` = 'localhost:8003') LIMIT 1;Executing (default): SELECT `domain`.`id`, `domain`.`host`, `domain`.`type`, `domain`.`clientSecret`, `domain`.`frontSecret`, `domain`.`createdAt`, `domain`.`updatedAt`, `domain`.`deletedAt`, `domain`.`userId`, `user`.`id` AS `user.id`, `user`.`email` AS `user.email`, `user`.`nick` AS `user.nick`, `user`.`password` AS `user.password`, `user`.`provider` AS `user.provider`, `user`.`snsId` AS `user.snsId`, `user`.`createdAt` AS `user.createdAt`, `user`.`updatedAt` AS `user.updatedAt`, `user`.`deletedAt` AS `user.deletedAt` FROM `domains` AS `domain` LEFT OUTER JOIN `users` AS `user` ON `domain`.`userId` = `user`.`id` AND (`user`.`deletedAt` > '2019-02-24 14:06:19' OR `user`.`deletedAt` IS NULL) WHERE ((`domain`.`deletedAt` > '2019-02-24 14:06:19' OR `domain`.`deletedAt` IS NULL) AND `domain`.`frontSecret` = NULL) LIMIT 1;POST /v2/token 401 53.205 ms - 100브라우저에서는 아래와 같이 나옵니다.code: 401message: "등록되지 않은 도메인입니다. 먼저 도메인을 등록하세요"도메인은 등록 해놓았는데 이런 오류가 나와서 오타인지 3번 정도 체크해봤는데 그건 아닌거 같아서 질문드립니다.
진성주
0
2