通过jwt向cognito用户池认证用户。
Flask-Cognito的Python项目详细描述
烧瓶白兰地
基于aws cognito jwt认证用户。
初始化
# configurationapp.config.extend({'COGNITO_REGION':'eu-central-1','COGNITO_USERPOOL_ID':'eu-central-1c3fea2',# optional'COGNITO_APP_CLIENT_ID':'abcdef123456',# client ID you wish to verify user is authenticated against'COGNITO_CHECK_TOKEN_EXPIRATION':False,# disable token expiration checking for testing purposes'COGNITO_JWT_HEADER_NAME':'X-MyApp-Authorization','COGNITO_JWT_HEADER_PREFIX':'Bearer',})# initialize extensioncogauth=CognitoAuth(app)@cogauth.identity_handlerdeflookup_cognito_user(payload):"""Look up user in our database from Cognito JWT payload."""returnUser.query.filter(User.cognito_username==payload['username']).one_or_none()
检查身份验证
fromflask_cognitoimportcognito_auth_required,current_user,current_cognito_jwt@route('/api/private')@cognito_auth_requireddefapi_private():# user must have valid cognito access or ID token in header# (accessToken is recommended - not as much personal information contained inside as with idToken)returnjsonify({'cognito_username':current_cognito_jwt['username'],# from cognito pool'user_id':current_user.id,# from your database})
确认
- 在其核心使用cognitojwt。
- 基于flask-jwt。