Giter VIP home page Giter VIP logo

tornado-alf's Introduction

tornado-alf build-status

Tornado OAuth 2 Client

tornado-alf is a OAuth 2 Client base on the tornado's AsyncHTTPClient

Features

  • Automatic token retrieving and renewing
  • Token expiration control
  • Automatic retry on status 401 (UNAUTHORIZED)

Usage

Initialize the client and use it as a AsyncHTTPClient object.

from tornadoalf.client import Client
from tornadoalf.httpclient import HTTPRequest

client = Client(
    token_endpoint='http://example.com/token',
    client_id='client-id',
    client_secret='secret')

resource_uri = 'http://example.com/resource'

response = await client.fetch(HTTPRequest(resource_uri),
    method='POST', body='{"name": "alf"}',
    headers={'Content-Type': 'application/json'})

Alternatively one can pass directly a string to the fetch client

# ...
response = await client.fetch('http://example.com/resource',
    method='POST', body='{"name": "alf"}',
    headers={'Content-Type': 'application/json'})

How it works?

Before any request the client tries to retrieve a token on the endpoint, expecting a JSON response with the access_token and expires_in keys.

The client keeps the token until it is expired, according to the expires_in value.

After getting the token, the request is issued with a Bearer authorization header:

GET /resource/1 HTTP/1.1
Host: example.com
Authorization: Bearer token

If the request fails with a 401 (UNAUTHORIZED) status, a new token is retrieved from the endpoint and the request is retried. This happens only once, if it fails again the error response is returned.

Troubleshooting

In case of an error retrieving a token, the error response will be returned, the real request won't happen.

Related projects

This project tries to be an adaptation to tornado of alf

tornado-alf's People

Contributors

marcelometal avatar mauriciosl avatar nsigustavo avatar pedrosnk avatar scorphus avatar vierno avatar wpjunior avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tornado-alf's Issues

tornado-alf 1.0.0 not published to pypi

It looks like version 1.0.0 was tagged on 12/20/2022 but was never published to pipy.

Running pip index versions tornado-alf shows the latest version published being v 0.4.4:
Screenshot from 2023-11-30 15-03-24

Currently the only way to use the latest version (which is needed if I want to use tornado 6+) is via git: pip install tornado-alf @ git+https://github.com/globocom/[email protected]#egg=tornado-alf

Would it be possible to get version 1.0.0 published to the python package index?

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.