2020. 5. 21. 01:47ㆍ카테고리 없음
쿠키는 조금 알겠는데, 세션과 토큰은 대체 왜 쓰는건지, 뭔지 잘 몰라서 검색하다가 너무 적절한 글을 발견했다.
그냥 읽어도 되지만, 경험 상 그냥 읽고 지나간 글은 기억 저편에 희미하게 남을 뿐이라서, 가볍게 번역해서 남겨두려고 한다. 영어 잘 못하니까, 대충 직역해서....
원본 글은 여기
https://medium.com/@sherryhsu/session-vs-token-based-authentication-11a6c5ac45e4
Session vs Token Based Authentication
Why do we need session or token for authentication?
medium.com
Session vs Token Based Authentication
인증 기반의 세션 vs 토큰
Why do we need session or token for authentication?
우리는 왜 인증을 위해서 세션이나 토큰을 쓸까?
HTTP is stateless. All the requests are stateless. However, there are situations where we would like our states to be remembered. For example, in a on-line shop, after we put bananas in a shopping cart, we don’t want our bananas to disappear when we go to another page to buy apples. ie. we want our purchase state to be remembered while we navigate through the on-line shop!
HTTP는 상태변화가 없다. 모든 요청(리퀘스트)은 상태변화가 없다. 그러나 때로는 우리의 상태가 기억되었으면 하는 경우가 있기 마련이다. 예를 들어, 온라인 쇼핑몰에서 바나나를 장바구니에 담고 나서 사과를 사려고 다른 페이지로 이동할 때, 우리는 장바구니의 바나나가 남아있었으면 한다. 온라인 쇼핑몰을 뒤적일 때 구매 상태(장바구니)가 기억되기를 원하는 것이다.
To overcome the stateless nature of HTTP requests, we could use either a session or a token.
상태변화가 없는 HTTP 요청에서 이를 극복하기 위해, 우리는 세션이나 토큰을 사용할 수 있다.
Session Based Authentication
인증 기반의 세션(인증을 위한 세션)
In the session based authentication, the server will create a session for the user after the user logs in. The session id is then stored on a cookie on the user’s browser. While the user stays logged in, the cookie would be sent along with every subsequent request. The server can then compare the session id stored on the cookie against the session information stored in the memory to verify user’s identity and sends response with the corresponding state!
인증 기반의 세션에서는 유저가 로그인하고 나서 해당 유저를 위해 서버가 세션을 하나 만든다. 만들어진 세션의 아이디는 유저가 로그인한 브라우저의 쿠키에 저장된다. 유저가 로그인 상태를 계속 유지하는 동안에, 쿠키는 이어지는 모든 요청을 따라가며 전송된다. 서버는 쿠키에 저장된 세션 아이디와 메모리(서버 측)에 저장된 세션 정보를 비교하여, 유저 정보(역자 주: 일반적인 유저 정보 말고, 유저와 다른 유저를 구분할 수 있도록하는 구분자가 되는 정보; identity)를 판별하고 이에 일치하는 응답을 보낸다.
Token Based Authentication
인증을 위한 토큰
Many web applications use JSON Web Token (JWT) instead of sessions for authentication. In the token based application, the server creates JWT with a secret and sends the JWT to the client. The client stores the JWT (usually in local storage) and includes JWT in the header with every request. The server would then validate the JWT with every request from the client and sends response.
많은 웹 어플리케이션들은 JSON 웹 토큰(JWT)을 세션 기반 인증 대신에 사용한다.(역자 주: 카카오도 그렇고, 요샌 다 그런 것 같습니다. 그래서 토큰이 대체 뭐길래 싶어서 이 글을 검색하게 된 것이다...) 토큰 기반 어플리케이션에서는 서버가 비밀스럽게 JWT를 만들어서 클라이언트에게 전송한다. 클라이언트는 JWT를 저장하고나서(일반적으로는 사용중인 기기 메모리에) JWT를 모든 요청의 헤더에 포함시킨다. 그러면 서버는 클라이언트 측의 모든 요청으로부터 받은 JWT를 검증하고 응답을 보낸다.
와...벌써 못하겠다... 어떻게 알아보기 쉽게 번역하냐고요.... 대충할란다 ㅠㅠ