성공적인 인증을 위해 passport-local을 결합하여 JWT 토큰을 반환하려면 어떻게해야합니까?passport-local with node-jwt-simple
node-jwt-simple을 사용하고 passport.js을보고 싶습니다. 어떻게 갈지 잘 모르겠습니다.
var passport = require('passport')
, LocalStrategy = require('passport-local').Strategy;
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username }, function(err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
}
));
done()을 호출 할 때 토큰을 반환 할 수 있습니까? 이 같은 뭔가 ... (단지 의사 코드)
if(User.validCredentials(username, password)) {
var token = jwt.encode({username: username}, tokenSecret);
done(null, {token : token}); //is this possible?
}
그렇지 않다면, 어떻게 내가 토큰을 반환 할 수 있습니다?
쿨, 감사를 다시 보내기 위해, 각도 사용하여 클라이언트 측에서 토큰을 처리하는 방법을 배울 중대하다 그것 : – robertklep
Passport의 [BasicStrategy] (http://passportjs.org/guide/basic-digest/) 또는 DigestStrategy는 다른 두 가지 옵션입니다. 하지만 기본 및 지역 전략 간에는 큰 차이가없는 것 같습니다. 세션이 작동하지 않아도됩니다. 즉, Local에서 리디렉션 URL을 요청 (API 친화력이 약간 떨어짐)하도록 요청하기 때문입니다. – funseiki
안녕하세요 @cgiacomi 토큰을 검사하는 경로의 예를 들려 줄 수 있습니까? –