Giter VIP home page Giter VIP logo

aiohttp-oauth's Introduction

aiohttp-oauth

OAuth middleware for your aiohttp app. Allows you to require logging in to an OAuth app in order to get to your app.

Installation

pip install aiohttp_oauth

Usage

Currently, only GitHub is supported.

First, you need to create a GitHub app. The callback url is your domain + /auth/oauth_callback

Basics

During the registration of your aiohttp app, just call the add_oauth_middleware and everything will be set up for you.

app = web.Application(loop=loop)
aiohttp_oauth.add_oauth_middleware(
    app,
    github_id='[your github client id]',
    github_secret='[your github secret]',
    github_org='[your github org]'
)

Configuring Cookies

If you would like to configure the cookies that this sets for your users, you can do that by setting cookie_key and cookie_name.

Example:

import aiohttp_oauth


app = web.Application(loop=loop)
aiogithubauth.add_oauth_middleware(
    app,
    github_id='[your github client id]',
    github_secret='[your github secret]',
    github_org='[your github org]',
    cookie_key='some 32 character string',
    cookie_name='some_cookie_name'
)

Custom OAuth Handler

You can create your own custom OAuth handler. It must implement the interface of aiohttp_oauth.auth.OauthHandler. Instantiate the object, and pass it into add_auth_middleware as the oauth_handler parameter.

Advanced

This middleware requires aiohttp_session middleware. The add_oauth_middleware method adds that for you. If you would instead like to add it yourself, you can add the githubauth middleware yourself.

Example:

from aiohttp_session import session_middleware
from aiohttp_session.cookie_storage import EncryptedCookieStorage
from aiohttp_oauth import oauth_middleware


app = web.Application(loop=loop, middlewares=[
    session_middleware(
           EncryptedCookieStorage(cookie_key.encode(),
                                  cookie_name=cookie_name,
                                  max_age=7200)),
    oauth_middleware(**kwargs),
    # ... 
])
# now add all your other handlers

Contributing

Pull requests are welcome. After cloning the repo you can run python setup.py develop to get Python to always point to your development version of the library. Now start your aiohttp server and you are in business.

aiohttp-oauth's People

Contributors

alairock avatar mattrasband avatar nhumrich avatar smddzcy avatar

Watchers

 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.