2016-11-07 4 views
1

Ionic2 프런트 엔드 및 노드/익스프레스/몽고 백엔드를 사용하고 있습니다. 사용자에게 로그인하기 위해 Passport 로컬 전략을 구성하고 제한된 끝점에 액세스하기 위해 사용자가 인증되었는지 확인하기 위해 간단한 미들웨어를 구성했습니다. 이 모든 것은 Postman 클라이언트에서 테스트 할 때 잘 작동합니다. 그러나 브라우저에서 로그인하고 끝점에 액세스하려고하면 오류가 발생합니다. 브라우저 (Chrome)가 "set-cookie"헤더의 쿠키 값을 반환하지만 Passport는 "쿠키"헤더의 쿠키 값을 찾은 것으로 보입니다. 내 응용 프로그램에서 GET 요청의 쿠키 헤더를 설정하려고했지만 보안상의 이유로이 작업을 수행 할 수 없습니다. 앱이 쿠키 헤더의 쿠키 값을 반환하도록하려면 어떻게해야합니까?여권 현지 전략이있는 사용자를 인증 할 수 없습니다.

Middleware 
function userAuthenticated(req, res, next){ 
    //returns value from Postman; undefined from app  
    console.log(req.get('Cookie').toString()); 
    //returns value from app; undefined from Postman 
    console.log(req.get('set-cookie').toString()); 

    if(req.isAuthenticated()){ 
     return next(); 
    } 
     res.send([{"message":"not logged in"}]); 
} 

Protected endpoint 
router.get('/books', userAuthenticated, function (req, res, next) { 
    Book.find({}, function(err, docs){ 
     if(err) { 
      res.send(err); 
     } else { 
      res.json(docs); 
      //next(); 
     } 
    }) 
}); 

답변