通过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})

确认

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
ApplyTransfermListener。Marklogic Java客户端Api中的ApplyResult?   java安卓:如何从服务调用方法   java如何在Junit中测试Servlet3.0注释基础servlet和嵌入Tomcat7   java在JSF中嵌入portlet   java检查多个向量是否是回文的?   Selenium Java页面对象模型查询   Java中运算符的优先级   java从包含透明像素的图像创建自定义JButton   hibernate Java类变量与其他变量的声明   安卓错误:任务执行失败:应用程序:mergeDebugResources'>JAVAlang.OutOfMemoryError:无法创建新的本机线程   java从localhost运行portlet   当用户输入索引时打印数组元素的java程序   在Windows 10上运行时出现java Blazegraph错误   javascript-spring有条件地加载资源