Skip to main content

ZeyticAuth Python SDK.

Project description

ZeyticAuth Python SDK

ZeyticAuth Stable Version PyPI - Python Version PyPI - License Discord

Prerequisites

  • Python 3.8 or higher
  • A ZeyticAuth Cloud account or a self-hosted ZeyticAuth
  • A ZeyticAuth traditional web application created

If you don't have the ZeyticAuth application created, please follow the ⚡ Get started guide to create one.

Installation

pip install zeytic # or `poetry add zeytic` or whatever you use

Tutorial

See tutorial for a quick start.

API reference

See API reference for more details.

Run the sample

There's a Flask sample in the samples directory. The sample has been tested with Python 3.8.17.

Install dependencies

This repo uses PDM as the package manager. To install the dependencies, run the following command in the root directory of the repo (not in the samples directory):

pdm install

Configure environment variables

To run the sample, you need to set the following environment variables:

APP_SECRET_KEY=your-secret-key # This is for Flask
ZEYTIC_ENDPOINT=http://your-zeytic-endpoint.com
ZEYTIC_APP_ID=your-zeytic-app-id
ZEYTIC_APP_SECRET=your-zeytic-app-secret
ZEYTIC_REDIRECT_URI=http://127.0.0.1:5000/sign-in-callback
ZEYTIC_POST_LOGOUT_REDIRECT_URI=http://127.0.0.1:5000/

Replace the values with your own.

For ZEYTIC_REDIRECT_URI and ZEYTIC_POST_LOGOUT_REDIRECT_URI, you should:

  1. Go to your ZeyticAuth Console and add the URIs to the application's settings accordingly.
  2. Update the domain and port to match your local environment if necessary.

[!Note] The sample project also support dotenv. You can create a .env file in the root directory of the sample project and add the environment variables there.

Run the sample

In the root directory of the repo, run the following command:

pdm run flask

The script can be found in the pyproject.toml file.

Fetch user information

Call client.getIdTokenClaims() to get the basic user info. For a more detailed user info, you can call client.fetchUserInfo().

For details on fetching user info, see the Get user information.

Route protection

You have many ways to accomplish this.

Directly check the user's authentication status

You can call client.isAuthenticated() to check if the user is authenticated and can proceed with the request.

Use a decorator

You can create a decorator like @authenticated() to protect your routes. A sample decorator can be found at samples/authenticated.py.

For instance, an API may throw a 401 error if the user is not authenticated:

from flask import g, jsonify

@app.route("/api/protected")
@authenticated()
def protected():
    print(g.user) # The `@authenticated()` decorator sets the user object in the `g` object
    return jsonify({"message": "This is a protected route"})

Or, you can redirect the user to the sign-in page:

from flask import g, jsonify

@app.route("/protected")
@authenticated(shouldRedirect=True)
def protected():
    return "This is a protected route"

See the flask.py file for more details.

Resources

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

zeytic-0.2.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zeytic-0.2.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file zeytic-0.2.1.tar.gz.

File metadata

  • Download URL: zeytic-0.2.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.2 Windows/11

File hashes

Hashes for zeytic-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3b8825a8de035ec53db0b1cee015fba350d91404940b0ef611154c838b935e43
MD5 bafd69e51e421578170506de06f32571
BLAKE2b-256 e5f98faba33f06a4cdf8ca61209d1552989b841686104c77b4915b303749e997

See more details on using hashes here.

File details

Details for the file zeytic-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: zeytic-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.2 Windows/11

File hashes

Hashes for zeytic-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc8c2b7bbdff285e3e03a24ab46d57096d342bc5d5f7b5473b9a9743deefe262
MD5 664caadd4766a4e8b9aa10df8bc65f9f
BLAKE2b-256 0bba07b67e74d49d796987fdcffdc1cb1d103704560e35504bbcc551a3355177

See more details on using hashes here.

Supported by

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