Skip to main content

FlaskOIDC

PyPI version License

This package relies purely on the Authlib package. Authlib

A wrapper of Flask with pre-configured OIDC support. Ideal for microservices architecture, each request will be authenticated using Flask's before_request middleware. Necassary endpoints can be whitelisted using an environment variable FLASK_OIDC_WHITELISTED_ENDPOINTS.

Installation:

pip3 install flaskoidc

Usage:

After simply installing the flaskoidc you can simply use it like below:

from flaskoidc import FlaskOIDC
app = FlaskOIDC(__name__)

Configurations:

Please make sure to extend your configurations from BaseConfig (only if you are sure what you are doing. Recommended way is to use the environment variables for the configuration.)

from flaskoidc import FlaskOIDC
from flaskoidc.config import BaseConfig

# Custom configuration class, a subclass of BaseConfig
CustomConfig(BaseConfig):
    DEBUG = True

app = FlaskOIDC(__name__)
app.config.from_object(CustomConfig)

Following ENVIRONMENT VARIABLES MUST be set to get the OIDC working.

FLASK_OIDC_PROVIDER_NAME

(default: 'google')

The name of the OIDC provider, like google, okta, keycloak etc. I have verified this package only for google, okta and keycloak. Please make sure to open a new issue if any of your OIDC provider is not working.

FLASK_OIDC_SCOPES

(default: 'openid email profile')

Scopes required to make your client works with the OIDC provider, separated by a space.

  • OKTA: make sure to add offline_access in your scopes in order to get the refresh_token.

FLASK_OIDC_USER_ID_FIELD

(default: 'email')

Different OIDC providers have different id field for the users. Make sure to adjust this according to what your provider returns in the user profile i.e., id_token.

FLASK_OIDC_CLIENT_ID

(default: '')

Client ID that you get once you create a new application on your OIDC provider.

FLASK_OIDC_CLIENT_SECRET

(default: '')

Client Secret that you get once you create a new application on your OIDC provider.

FLASK_OIDC_REDIRECT_URI

(default: '/auth')

This is the endpoint that your OIDC provider hits to authenticate against your request. This is what you set as one of your REDIRECT URI in the OIDC provider client's settings.

FLASK_OIDC_CONFIG_URL

(default: '')

To simplify OIDC implementations and increase flexibility, OpenID Connect allows the use of a "Discovery document," a JSON document found at a well-known location containing key-value pairs which provide details about the OpenID Connect provider's configuration, including the URIs of the authorization, token, revocation, userinfo, and public-keys endpoints.

Discovery Documents may be retrieved from:

  • Google: https://accounts.google.com/.well-known/openid-configuration
  • OKTA
    • https://[YOUR_OKTA_DOMAIN]/.well-known/openid-configuration
    • https://[YOUR_OKTA_DOMAIN]/oauth2/[AUTH_SERVER_ID]/.well-known/openid-configuration
  • Auth0: https://[YOUR_DOMAIN]/.well-known/openid-configuration
  • `Keycloak: http://[KEYCLOAK_HOST]:[KEYCLOAK_PORT]/auth/realms/[REALM]/.well-known/openid-configuration

A few other environment variables along with their default values are.

# Flask `SECRET_KEY` config value
FLASK_OIDC_SECRET_KEY: '!-flask-oidc-secret-key'

# Comma separated string of URLs which should be exposed without authentication, else all request will be authenticated.
FLASK_OIDC_WHITELISTED_ENDPOINTS: "status,healthcheck,health"

You can also set the config variables specific to Flask-SQLAlchemy using the same key as the environment variables.

# Details about this below in the "Session Management" section.
SQLALCHEMY_DATABASE_URI: 'sqlite:///sessions.db'

Known Issues:

  • Need to make sure it still works with the clients_secrets.json file or via env variables for each endpoint of a custom OIDC provider.
  • refresh_token is not yet working. I am still trying to figure out how to do this using Authlib.
  • You may enter problems when installing cryptography, check its official document

Metadata

Release files for adsk-flaskoidc 1.0.4

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

Source distribution (sdist)

Source distribution for adsk-flaskoidc 1.0.4
File Size Uploaded Provenance Actions
adsk-flaskoidc-1.0.4.tar.gz 6.8 kB Without provenance Details for adsk-flaskoidc-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for adsk-flaskoidc 1.0.4
File Interpreter ABI Platform Actions
adsk_flaskoidc-1.0.4-py3-none-any.whl Python 3 none any Details for adsk_flaskoidc-1.0.4-py3-none-any.whl

Total release size: 18.5 kB

Release files / adsk-flaskoidc-1.0.4.tar.gz

Download URL adsk-flaskoidc-1.0.4.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6afa57173a53d0b002df4ef7a393c9c238a6939d03dba556d31378ab51233437
BLAKE2b-256 checksum
How to use checksums
e4624b1bc30dae4e4f5ef5689148f853bc6c8918546373232d5f906d7464f37b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

Release files / adsk_flaskoidc-1.0.4-py3-none-any.whl

Download URL adsk_flaskoidc-1.0.4-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8aa4fa0bc86f90858ecf9803794c2ed24a396830a1128b8c73a9317f0af9cc57
BLAKE2b-256 checksum
How to use checksums
1c402c20e81ce4dfdb8f5ad75240035d76e3e61b6256113b2f3b8801aca5db2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

Security for adsk-flaskoidc 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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