Skip to main content

Python library to help manage your Passage application and users

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

passage-python

This Python SDK allows for verification of server-side authentication for applications using Passage

Install this package using pip.

pip install passage-identity

Instantiating the Passage Class

Passage has three arguments that can be used for initialization: app_id, api_key, and auth_strategy.

  • app_id is the Passage App ID that specifies which app should be authorized. It has no default value and must to be set upon initialization.
  • api_key is an API key for the Passage app, which can be generated in the 'App Settings' section of the Passage Console. It is an optional parameter and not required for authenticating requests. It is required to get or update user information.
  • auth_strategy defines where the Passage SDK should look for the authentication token. It is set by default to Passage.COOKIE_AUTH, but can be changed to Passage.HEADER_AUTH.

Authenticating a Request

To authenticate an HTTP request in a Flask application, you can use the Passage library in a middleware function. You need to provide Passage with your app ID in order to verify the JWTs.

from passageidentity import Passage
import os

PASSAGE_APP_ID_ = os.environ.get("PASSAGE_APP_ID")

def exampleFlaskMiddleware(request):
    psg = Passage(PASSAGE_APP_ID)
    user = psg.authenticateRequest(request)

Retrieve User Info

To retrieve information about a user, you should use the getPassageUser method. You will need to use a Passage API key, which can be created in the Passage Console under your Application Settings. This API key grants your web server access to the Passage management APIs to get and update information about users. This API key must be protected and stored in an appropriate secure storage location. It should never be hard-coded in the repository.

from passageidentity import Passage
import os

PASSAGE_APP_ID = os.environ.get("PASSAGE_APP_ID")
PASSAGE_API_KEY = os.environ.get("PASSAGE_API_KEY")
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

def exampleFlaskMiddleware(request):
    g.user = psg.authenticateRequest(request)

@auth.route('/home')
def authenticatedEndpoint():
    user = psg.getPassageUser(g.user)
	print(user.email)

The information available in the Passage User object is as

Field Type
id string
email string
phone string
active boolean
email_verified boolean
created_at Datetime
last_login_at Datetime
webauthn boolean
webauthn_devices array
recent_events array of PassageEvents

Activate/Deactivate User

You can also activate or deactivate a user using the Passage SDK. These actions require an API Key and deactivating a user will prevent them from logging into your application with Passage.

from passageidentity import Passage
import os

PASSAGE_APP_ID = os.environ.get("PASSAGE_APP_ID")
PASSAGE_API_KEY = os.environ.get("PASSAGE_API_KEY")
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

# Get Passage User ID from database
# ...

#activate or deactivate this user
psg.deactivateUser(user_id)

Update User Attributes

You can also update a user's attributes using the Passage SDK. This will require a Passage API Key.

from passageidentity import Passage
import os

PASSAGE_APP_ID = os.environ.get("PASSAGE_APP_ID")
PASSAGE_API_KEY = os.environ.get("PASSAGE_API_KEY")
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

# Get Passage User ID from database
# ...

# update a user's email
psg.updateUser(user_id, {
    "email": "newEmail@domain.com",
    "phone": "+15005550006"
})

Create User

You can also create users using their email address or phone number. Note that their phone number must be in E164 format (example shown below).

from passageidentity import Passage
import os

PASSAGE_APP_ID = os.environ.get("PASSAGE_APP_ID")
PASSAGE_API_KEY = os.environ.get("PASSAGE_API_KEY")
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

# Get Passage User ID from database
# ...

# create a user via their email
psg.createUser({"email": "exampleEmail@domain.com"})

# create a user via their phone number
psg.createUser({"phone": "+15005550007"})

Delete User

from passageidentity import Passage
import os

PASSAGE_APP_ID = os.environ.get("PASSAGE_APP_ID")
PASSAGE_API_KEY = os.environ.get("PASSAGE_API_KEY")
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

# Get Passage User ID from database
# ...

# delete a user via their userID
deleted_user = psg.deleteUser(user_id)
if deleted_user:
    print("User has been deleted")

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

passage-identity-1.1.4.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

passage_identity-1.1.4-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file passage-identity-1.1.4.tar.gz.

File metadata

  • Download URL: passage-identity-1.1.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for passage-identity-1.1.4.tar.gz
Algorithm Hash digest
SHA256 543126f04bc44083eae21fcee28ac1402df697c97200ba0d872b6bbd6312cb11
MD5 cb96a0164c0ce832b6bb4728ece628a3
BLAKE2b-256 88af5b6f29ea4834cfba7d8f80a8c2015eeaa2e2700d68a9e44420dba713d391

See more details on using hashes here.

File details

Details for the file passage_identity-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: passage_identity-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for passage_identity-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 79cd2071ac99e1a2129b91c8d06dfda9ca664d670b4365acc3fc12f1b95db14f
MD5 edc0d2663c00166cf203b90539b1fb12
BLAKE2b-256 d738a4c355dd2748c6bf9c55d086cbc20d2be2de941fa1635bd1b28ca3b7ba8f

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