curityio/example-python-openid-connect-client

Repository files navigation

QualityAvailability

This is a demo application to explain how the OpenID Connect code flow is implemented.

$ python app.py

Flask will start a web server listening on all interfaces that can be used for demo purposes. The webserver will use HTTPS with a certificate for localhost. Browse to https://localhost:5443 to see the app.

python 3.x (tested with python 3.9.1)

OpenSSL 1.0 to be able to do modern TLS versions. Python together with 0.9.x has a bug that makes it impossible to select protocol in the handshake, so it cannot connect to servers that have disabled SSLv2.

Python dependencies can be installed by using PIP: pip install -r requirements.txt

Settings.json is used as a configuration file for the example app. Change the values to match your system.

NameTypeDefaultDescription
issuerstringThe ID of the token issuer. This is used for both OpenID Connect Discovery, and validating a ID Token. Mandatory for discovery
client_idstringThe ID for the client. Used to authenticate the client against the authorization server endpoint.
client_secretstringThe shared secret to use for authentication against the token endpoint.
dcr_client_idstringThe client ID of the client for to use for registration.
dcr_client_secretstringThe client secret of the client for to use for registration.
scopestringopenidThe scopes to ask for.
verify_ssl_serverbooleantrueSet to false to disable certificate checks.
debugbooleanfalseIf set to true, Flask will be in debug mode and write stacktraces if an error occurs. Some extra logging is also printed.
portnumber5443The port that the Flask server should listen to
disable_httpsbooleanfalseSet to true to run on http
base_urlstringbase url to be added to internal redirects. If this is not configured, the base url will be extracted from the first request to the index page
send_parameters_viastringquery_stringHow request parameters should be sent to the authorization endpoint. Valid values are query_string, request_object or request_uri.
request_object_keysJSON objectThe JSON Web Key (JWK) used to sign JWTs used when sending authorization request parameters by-value in a request object or by reference in a request URI. For example:
{
"kty":"RSA",
"n":"0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4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b_d9GF4Dh7e74WbRsobRonujTYN1xCaP6TO61jvWrX-L18txXw494Q_cgk",
"qi":"GyM_p6JrXySiz1toFgKbWV-JdI3jQ4ypu9rbMWx3rQJBfmt0FoYzgUIZEVFEcOqwemRN81zoDAaa-Bk0KWNGDjJHZDdDmFhW3AN7lI-puxk_mHZGJ11rxyR8O55XLSe3SPmRfKwZI6yU24ZxvQKFYItdldUKGzO6Ia6zTKhAVRU",
"alg":"RS256",
"kid":"2011-04-29"
}
NameTypeDescription
jwks_uriURLThe URL that points to the JWK set. Mandatory if the openid scope is requested.
authorization_endpointThe URL to the authorization endpoint.
token_endpointURLThe URL to the token endpoint.
registration_endpointURLThe URL to the registration endpoint.

To run the example in a Docker container, build an image and run a container like this.:

$ docker build -t curityio/openid-python-example .
$ docker run -ti curityio/openid-python-example

All setting can be set using an environment variable with uppercase letters. Example:

$ docker build -t curityio/openid-python-example
$ docker run -e DEBUG=true -e ISSUER=se.curity -ti curityio/openid-python-example

In the root of the repository, there is a docker-compose.yml. Customize the settings using environment variables with uppercase letters.

$ docker-compose up

For questions and support, contact Curity AB:

Curity AB

[email protected] https://curity.io

Copyright (C) 2016 Curity AB.

About

An example website that implements OAuth 2.0 and OpenID Connect in Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 9