aws cognito的异步包装器。主要基于无上限/认股权证
mandate的Python项目详细描述
授权
异步叉warrant
部分代码是由warrant贡献者作为该软件的一部分提供的根据apache许可证2.0的允许,这里已经复制了此代码。授权代码是授权贡献者的版权任何其他代码都是授权贡献者的版权
初始化
cog=Cognito('pool_id',# user pool id'client_id',# client iduser_pool_region='eu-west-2',# optionalusername='your-user@email.com',client_secret='secret',# optionalloop=loop# optional)
寄存器
cog.add_base_attributes(email='your-user@email.com')awaitcog.register('your-user@email.com','password')
admin_create_user
也可用:
awaitcog.admin_create_user('user@email.com')
确认注册
awaitcog.confirm_sign_up('SIGNUP_CODE','your-user@email.com')
admin_confirm_sign_up
也可用:
awaitcog.admin_confirm_sign_up('user@email.com')
验证
下面的所有示例都可以使用或不使用admin_
变量调用
根据the documentation,在运行后端服务器时,可以使用admin_
方法进行身份验证和与用户相关的活动。例如:
awaitcog.admin_authenticate(password)
技术上,非管理工作流也可以使用,但我还没有得到这个工作与应用程序机密!如果你能帮忙,我将不胜感激
awaitcog.authenticate(password)
botocore.errorfactory.NotAuthorizedException: An error occurred (NotAuthorizedException) when calling the RespondToAuthChallenge operation: Unable to verify secret hash for client <client id>
如果您创建的应用程序没有应用程序机密,您也应该能够使用非管理版本没有问题。
忘记密码
awaitcog.initiate_forgot_password()# Get the code from the emailawaitcog.confirm_forgot_password(code,new_password)
获取用户属性
awaitcog.admin_authenticate('password')user=awaitcog.get_user()
更改密码
awaitcog.admin_authenticate(old_password)awaitcog.change_password(old_password,new_password)
更新配置文件
awaitcog.admin_authenticate(password)awaitcog.update_profile({'address':'foo'})
或作为管理员
awaitcog.admin_update_profile(username='other-user',attrs={'gender':'potato'})
注销
awaitcog.logout()
开发
安装poetry,然后安装 依赖关系:
poetry install
单元测试
python-m unittest发现测试