Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

ackerleytng/requests-keycloak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

requests-keycloak

Makes requests take the role of a User-Agent (as defined in the OAuth 2.0 world), automatically logs in to keycloak using a username and password configured as environment variables.

requests-keycloak is intended as a stopgap replacement for the use of API keys, where the API keys are meant to both authenticate and provide authorization in the OAuth world.

This project, as is, does not correctly "replay" the original request to the OAuth 2.0 client, the POST data from the original request is lost. After digging into it a bit more, I found that this isn't the solution that I want. See explanation on stackoverflow.

Usage

Without requests-keycloak, you would have done

Python 3.7.4 (default, Sep  7 2019, 18:27:02)
>>> import requests
>>> r = requests.get('https://api.github.com/repos/psf/requests')
>>> r.json()["description"]
'A simple, yet elegant HTTP library.'

With requests-keycloak,

Python 3.7.4 (default, Sep  7 2019, 18:27:02)
>>> import requests
>>> r = requests.get('https://secured.example/keycloak/protected/endpoint, auth=KeycloakAuth())
>>> r.json()["description"]
'Convenient!'

Or try our examples!

Examples

Start the dev environment

$ cd dev-environment
$ docker-compose up -d  # Starts keycloak, creates a OAuth client for httpbin

Try accessing

https://httpbin.localhost/anything

in your browser - you'll have to login with user0 and password, and you'll have to change your password.

Run the examples:

AUTOLOGIN_USERNAME=user0 AUTOLOGIN_PASSWORD=password python examples/using_keycloak_auth.py
AUTOLOGIN_USERNAME=user0 AUTOLOGIN_PASSWORD=password python examples/using_keycloak_session.py
AUTOLOGIN_USERNAME=user0 AUTOLOGIN_PASSWORD=password python examples/using_keycloak_session_post.py

About

Helps requests automatically sign in to Keycloak (turns requests into a User Agent in the OAuth world)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published