Skip to main content

authenticate with cognito backend

Project description

villaAuthSdk

interact with villa authentication backend

Install

pip install villaAuthSdk

How to use

create an auth object

from villaAuthSdk.auth import AuthSdk
from nicHelper.dictUtil import printDict
sdk=AuthSdk(user=None,pw=None,region='ap-southeast-1')
## user and pw here are the aws key/secret for your client

Create cashier

sdk.createCashier({
  'user': 'nic1',
  'phone': '+66816684442',
  'pw': '12345678',
  'name': 'nic',
  'cashierCode': '001',
  'email': 'test@gmail.com'
})
{'success': True,
 'user': 'nic1',
 'phone': '+66816684442',
 'pw': '12345678',
 'name': 'nic',
 'cashierCode': '001',
 'email': 'test@gmail.com',
 'body': '{"Username":"nic1","UserAttributes":{"sub":"f5aa60ba-0f65-45f3-b8f7-2a064e7e5311","email_verified":"false","name":"nic","custom:cashierCode":"001","phone_number_verified":"true","phone_number":"+66816684442","email":"test@gmail.com"},"UserCreateDate":1606995525.734,"UserLastModifiedDate":1606995525.988,"Enabled":true,"UserStatus":"CONFIRMED","ResponseMetadata":{"RequestId":"6b2010b5-aabc-4d36-8e3e-0234da56f3ab","HTTPStatusCode":200,"HTTPHeaders":{"date":"Thu, 03 Dec 2020 11:38:46 GMT","content-type":"application\\/x-amz-json-1.1","content-length":"467","connection":"keep-alive","x-amzn-requestid":"6b2010b5-aabc-4d36-8e3e-0234da56f3ab"},"RetryAttempts":0}}',
 'statusCode': 200,
 'headers': {'Access-Control-Allow-Headers': '*',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': '*'}}

login

result = sdk.auth(user='nic1',pw='12345678')
printDict(result)
AccessKeyId : ASIAVX4Z5T
SecretKey : zTt7RyFFji
SessionToken : IQoJb3JpZ2
Expiration : 1606999129.0
AccessToken : eyJraWQiOi
ExpiresIn : 3600
TokenType : Bearer
RefreshToken : eyJjdHkiOi
IdToken : eyJraWQiOi
NewDeviceMetadata
 DeviceKey : ap-southea
 DeviceGroupKey : -lt0cpemm
userInfo
 Username : nic1
 UserCreateDate : 1606995525.734
 UserLastModifiedDate : 1606995525.988
 Enabled : True
 UserStatus : CONFIRMED
 ResponseMetadata
  RequestId : 44425d05-8
  HTTPStatusCode : 200
  HTTPHeaders
   date : Thu, 03 De
   content-type : applicatio
   content-length : 467
   connection : keep-alive
   x-amzn-requestid : 44425d05-8
  RetryAttempts : 0
kwUserAttrib
 sub : f5aa60ba-0
 email_verified : false
 name : nic
 custom:cashierCode : 001
 phone_number_verified : true
 phone_number : +668166844
 email : test@gmail

Confirm

confirm phone/email

result=sdk.confirm(user='nic1', code= '123')
printDict(result)
error
 pickledb64string : gASVTQUAAA
 error : confirmati

Get Profile

result=sdk.getProfile('nic1')
printDict(result)
Username : nic1
UserAttributes
 sub : f5aa60ba-0
 email_verified : false
 name : nic
 custom:cashierCode : 001
 phone_number_verified : true
 phone_number : +668166844
 email : test@gmail
UserCreateDate : 1606995525.734
UserLastModifiedDate : 1606995525.988
Enabled : True
UserStatus : CONFIRMED
ResponseMetadata
 RequestId : 85a734ac-2
 HTTPStatusCode : 200
 HTTPHeaders
  date : Thu, 03 De
  content-type : applicatio
  content-length : 467
  connection : keep-alive
  x-amzn-requestid : 85a734ac-2
 RetryAttempts : 0

update Profile

result = sdk.updateProfile(
  user= 'nic1',
  attributes= {
    'custom:cashierCode': '1234'
  })
printDict(result)
Username : nic1
UserAttributes
 sub : f5aa60ba-0
 email_verified : false
 name : nic
 custom:cashierCode : 1234
 phone_number_verified : true
 phone_number : +668166844
 email : test@gmail
UserCreateDate : 1606995525.734
UserLastModifiedDate : 1606995533.461
Enabled : True
UserStatus : CONFIRMED
ResponseMetadata
 RequestId : ec6ffad2-1
 HTTPStatusCode : 200
 HTTPHeaders
  date : Thu, 03 De
  content-type : applicatio
  content-length : 468
  connection : keep-alive
  x-amzn-requestid : ec6ffad2-1
 RetryAttempts : 0

set password

sdk.setPassword(user='nic1',pw='12345678')
{'ResponseMetadata': {'RequestId': 'e878f2d6-d1de-487c-8a0a-484072b82309',
  'HTTPStatusCode': 200,
  'HTTPHeaders': {'date': 'Thu, 03 Dec 2020 11:38:54 GMT',
   'content-type': 'application/x-amz-json-1.1',
   'content-length': '2',
   'connection': 'keep-alive',
   'x-amzn-requestid': 'e878f2d6-d1de-487c-8a0a-484072b82309'},
  'RetryAttempts': 0}}

Unauth

get unauthenticated credentials

result = sdk.unauth()
printDict(result)
AccessKeyId : ASIAVX4Z5T
SecretKey : UbsJ2mlM3z
SessionToken : IQoJb3JpZ2
Expiration : 1606999136.0

DeleteUser

result = sdk.deleteUser(user='nic1')
printDict(result)
ResponseMetadata
 RequestId : 7e3fc4ac-5
 HTTPStatusCode : 200
 HTTPHeaders
  date : Thu, 03 De
  content-type : applicatio
  content-length : 0
  connection : keep-alive
  x-amzn-requestid : 7e3fc4ac-5
 RetryAttempts : 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

villaAuthSdk-0.0.12.tar.gz (12.5 kB view hashes)

Uploaded Source

Built Distribution

villaAuthSdk-0.0.12-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page