Git Product home page Git Product logo

flask-indieauth's Introduction

Flask-IndieAuth

This extension adds the ability to authorize requests to your Flask endpoints via IndieAuth, using current_app.config['TOKEN_ENDPOINT'] as the token server.

This is useful for developers of Micropub server implementations.

Configuration

current_app.config should contain the following configuration details:

TOKEN_ENDPOINT

(e.g. "https://tokens.indieauth.com/token")

ME

(e.g. "http://example.com")

Example Usage:

from flask_indieauth import requires_indieauth
@app.route('/micropub', methods=['GET','POST'])
@requires_indieauth
def handle_micropub():
    ...

When a Flask route is wrapped in @requires_indieauth, this extension will look for an IndieAuth bearer token in these locations in order:

  • HTTP header Authorization: Bearer xxx...
  • HTTP form data in the parameter access_token
  • HTTP POST body, if in JSON format, in the access_token attribute

If an access token is found, it is checked for a me value equal to the domain in current_app.config["ME"] and a scope value of post.

If all checks pass, processing is passed to the Flask route handler.

Access Token Contents

Upon successful authentication/authorization, Flask-IndieAuth will store a user dict in Flask.g with the following attributes:

me

the homepage that the user logged in as

scope

the authorization scope of this token

client_id

typically the homepage for the micropub client

access_token

the raw access token

Example Usage:

from flask import g, current_app

from flask_indieauth import requires_indieauth
@app.route('/micropub', methods=['GET','POST'])
@requires_indieauth
def handle_micropub():
    user = g.user
    current_app.logger.info("Request from %s" % user["me"])

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.