본문 바로가기

BackEnd

API - Flask에서 JWT 설치방법

반응형
JWT

 

 

JSON Web Token

 

JWT is used for user authentication and is passed between the user and the server.

A JWT is a string composed of the header, payload, and signature

 

 

https://jwt.io/

 

JWT.IO

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

jwt.io

 

 

 

 

 

인증 흐름 설명

 

클라이언트와 서버간의 인증토큰 흐름

 

 

 

회원가입 / 로그인시 토큰 발행

 

발행된 토큰을 클라이언트에서 저장하고

 

이를 인증 필요한 API 호출에 사용한다.

 

 

 

 

Flask에서 JWT 설치방법

 

 

 

$ pip install flask-jwt-extended

 

 

옵션 설명

 

https://flask-jwt-extended.readthedocs.io/en/latest/options/

 

Configuration Options — flask-jwt-extended 4.4.1 documentation

Configuration Options You can change many options for this extension works via Flask’s Configuration Handling. For example: app.config["OPTION_NAME"] = option_value General Options: JWT_TOKEN_LOCATION Where to look for a JWT when processing a request. Th

flask-jwt-extended.readthedocs.io

 

 

이 라이브러리는 다음 3개를 제공한다.

 

create_access_token()

@jwt_required(optional = False) : 무조건 토큰 필요, optional을 True로 하면 상관 없다는 뜻.

get_jwt_identity()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형