Skip to main content

This package is completely built by https://github.com/pop-srw/streamlit-cognito-auth/. I needed an urgent fix, the pull request and PyPi packaging will take time from original contributor, therefore I created a separate package. This package will be deleted as soon as the original package is updated.

Streamlit Cognito Auth

A Streamlit component for authenticating users with AWS Cognito

Installation

To install the package, you can use pip:

pip install stcog

Usage

To use the package, you can import the CognitoAuthenticator class from the streamlit_cognito_auth package, and create an instance of it, passing your pool_id, app_client_id and app_client_secret as the arguments.

from stcog import CognitoAuthenticator

To perform login, you can call the login() method on the authenticator instance and check the returned value, if it's True then the user is logged in, otherwise the login process failed.

is_logged_in = authenticator.login()
if not is_logged_in:
    print("Login failed")

To perform logout, you can call the logout() method on the authenticator instance

authenticator.logout()

You can also get the logged in user's username by calling get_username() method on the authenticator instance

username = authenticator.get_username()

You can find the full example code in examples/example.py file.

Example

You can find an example of how to use the package in the examples directory.

To run the example file, you can use the following command, while replacing your_pool_id, your_app_client_id and your_app_client_secret with the actual values:

export POOL_ID="your_pool_id"
export APP_CLIENT_ID="your_app_client_id"
export APP_CLIENT_SECRET="your_app_client_secret"

cd examples
streamlit run example.py

or in windows

set POOL_ID="your_pool_id"
set APP_CLIENT_ID="your_app_client_id"
set APP_CLIENT_SECRET="your_app_client_secret"

cd examples
streamlit run example.py

login Login

logout Logout

Login with temporary password Login with temporary password

Reset password and login Login with temporary password

Limitations

  • This package has been tested and known to work with Amazon Cognito pools that have an app client with a secret enabled and using the SRP protocol. Other configurations of Cognito pools may not be supported and have not been tested.
  • This package has been tested and known to work with python 3.8 in Linux environment. It may not work with other versions of python or other operating systems.

Features

  • Support for Cognito pools with app client secret
  • Support for Cognito pools without app client secret
  • Support for "USER_SRP_AUTH" authentication flow
  • Support for "REFRESH_TOKEN_AUTH / REFRESH_TOKEN" authentication flow
  • Support for "USER_PASSWORD_AUTH" authentication flow
  • Support for password reset for temporary password
  • Support for password reset with OTP
  • Support for Cognito hosted UI

Credits

  • This package is completely built by https://github.com/pop-srw/streamlit-cognito-auth/. I needed an urgent fix, the pull request and PyPi packaging will take time from original contributor, therefore I created a separate package.
  • Below contributions are listed by original creator https://github.com/pop-srw/streamlit-cognito-auth/
  • This package is inspired by the work of mkhorasani/Streamlit-Authenticator, and we would like to thank the author for their work.
  • JWT verification functionality is based on the work of awslabs/aws-support-tools, and we would like to thank the author for their work.
  • This package uses the pycognito library for authentication, which is a Python library that provides a simple interface for working with AWS Cognito. We would like to express our gratitude to the authors of pycognito for their work and for providing an excellent library for working with AWS Cognito.
  • We would also like to thank OpenAI's ChatGPT for providing helpful suggestions and examples throughout the development of this project.
  • Special thanks to mrtj for the nice hosted UI feature. (#6)

Metadata

Release files for stcog 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stcog 0.0.7
File Size Uploaded
stcog-0.0.7.tar.gz 12.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stcog 0.0.7
File Interpreter ABI Platform
stcog-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 27.1 kB

Release files / stcog-0.0.7.tar.gz

Download URL stcog-0.0.7.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e69baf962ab92a9345afcf6096846b513a5ab9ceddace7063a6ca5c5efcdae11
BLAKE2b-256 checksum
How to use checksums
068b2f6b51e5bdf421922cbd77b834fe3e7b5d2a26f73748cce02e3ec2dd4053
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release files / stcog-0.0.7-py3-none-any.whl

Download URL stcog-0.0.7-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7b49f9c3e5a274d85ae6601dc05f32dc026d4a2fa822d6c58684f7687bb5212
BLAKE2b-256 checksum
How to use checksums
b4f568e04fcfc2db68781dfb6ac267100b553761ce278ba322be713184276be9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page