-
Node-passport프로그래밍/Node 2021. 3. 10. 17:25
목적
Node 기본 강의에서 passport package를 소개 하였는데, 뭔 내용인지 하나도 모르겠더라..
그래서 직접 해당 doc문서를 보면서 정리를 하였다.
이 글을 작성하면서도 이 모듈을 제대로 이해를 못해서 (너무어려움)
반복해서 정리한 내용을 보고자 한다. 영어 독해 실력도 키우기 위해 영어로 포스팅한다.
Passport is authentication middleware for Node.js
Authenticate
Authenticating requests is as simple as calling passport.authenticate() and specifying which strategy to employ.
By default, if authentication fails, Passport will respond with a 401 Unauthorized status, and any additional route handlers will not be invoked. If authentication succeeds, the next handler will be invoked and the req.user property will be set to the authenticated user.
Three pieces need to be configured to use Passport for authentication:
- Authendication Strategies
- Application middleware
- Sessions
Authendication Strategies
Strategies must be configured prior to using them in a route.
Strategies, and their configuration, are supplied via the use() function.
When Passport authenticates a request, it parses the credentials contained in the request. It then invokes the verify callback with those credentials as arguments, in this case username and password. If the credentials are valid, the verify callback invokes done to supply Passport with the user that authenticated.
Application middleware
In a Express-based application, passport.initialize() middleware is required to initialize Passport. If your application uses persistent login sessions, passport.session() middleware must also be used.
Sessions
In a typical web application, the credentials used to authenticate a user will only be transmitted during the login request. If authentication succeeds, a session will be established and maintained via a cookie set in the user's browser.
'프로그래밍 > Node' 카테고리의 다른 글
Blocking vs Non-Blocking (0) 2021.07.20 이벤트 루프? (0) 2021.07.04 Node.js - 비동기 중심 모델 (0) 2021.06.26 NodeJs란 (0) 2021.05.14