Giter Site home page Giter Site logo

ddubson / sample-oauth2-py Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 28 KB

Sample OAuth 2.0 Client, OAuth 2.0 Resource Server based on Python and Authlib

Makefile 8.64% Python 66.76% Dockerfile 3.20% Shell 0.70% HTML 20.70%
python3 authlib oauth2-client oauth2-resource-server

sample-oauth2-py's Introduction

Sample Python-based OAuth 2.0 Client and OAuth 2.0 Resource Server

Getting started

๐ŸŽŸ Pre-requisites

  • GNU Make

๐Ÿ”Œ Initial startup:

# Ensure environment is created
make bootstrap

# Activate the environment
. venv/bin/activate

# Create a valid .env file
cp .env.template .env

Fill in the details of the .env file as per template.

OAuth 2.0 Client (Web - Django)

The sample OAuth 2.0 Client is built with Authlib Django library support

Starting the client

make client-serve
# Starts on port **8000**
open http://127.0.0.1:8000/client_app

๐Ÿง‘โ€๐Ÿณ How it's made

๐Ÿ›’ On the OAuth 2.0 Client side

  • The client can be found in the client directory in the root of this repository
  • Django has the concept of sites and apps, so:
    • The site is located in client/client_site
    • The one and only app is located in client/client_app
  • ๐Ÿ’Ž Observe the global client configuration in authlib_registered_oauth2_clients in client/client_site/oauth2_clients.py
    • The client definitions are passed to Authlib via environment variable set in client/client_site/settings.py
  • ๐Ÿ’Ž Observe the OAuth client definition in client/client_app/oauth2.py
    • The OAuth clients defined are passed to client/client_app/views.py for use.
  • ๐Ÿ’Ž By default, the client is wired up with name messaging_client
  • โญ๏ธ Observe the available endpoints for the client application at client/client_app/urls.py

๐Ÿ”‘ On the OAuth 2.0 Authorization Server side (bring your own):

  • Make sure to configure a client registration with name messaging_client that:
    • includes scopes openid and message.read
    • includes redirects like the following (change the host name as needed):
      • http://127.0.0.1:8000/client_app/authenticated (for OpenID authentication)
      • http://127.0.0.1:8000/client_app/auth-code-authorized (for Authorization Code grant type)
    • โš ๏ธ Make sure you don't confuse localhost and 127.0.0.1 loopback address. When in doubt, rely on 127.0.0.1 when setting up redirects and navigating in the browser.

Resources


OAuth 2.0 Resource Server (REST API - Flask 2.x)

The sample OAuth 2.0 Resource Server is built with Authlib Flask 2.0 library support

Operation

Starting the resource server

make resourceserver-serve
# Starts on port **8001**

To independently verify that your protected resources are fetchable given an access token, run:

jq command is required.

./resourceserver/scripts/test-access-token.sh <JSON_WEB_TOKEN_STRING>

client_id, client_secret, and token_introspection_endpoint variables must be set in .env file

Resources

sample-oauth2-py's People

Contributors

ddubson avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.