Skip to main content

Securely redirects OAuth responses to known clients.

Project description

Description

During the OAuth workflow a webserver defined by redirect_uri receives the result of a the authorization given by the enduser.

This redirect_uri is usually a whitelisted uri to avoid phising attacks.

Unfortunately this makes it hard to write an OAuth integrated client to an API where the domain is not known in advance.

Faced with such a situation we wrote this server to move the decision of who can receive the result of an OAuth handshake from the OAuth provider to an intermediary.

How it Works

Using oauth_redirect the OAuth workflow works as follows:

  1. The oauth_redirect server is run on a TLS protected site. For example: https://oauth.seantis.ch.

  2. The OAuth provider is configured to allow redirects to https://oauth.seantis.ch/redirect.

  3. The client that wants to acquire the authorisation registers itself with the oauth_redirect server using a secret authentication code.

  4. The enduser is presented with the OAuth authorization site, with the redirect_uri set to https://oauth.seantis.ch/redirect.

  5. The result is sent to the oauth_redirect server, which will forward/proxy the request to the client, if and only if the client has registered itself before and the request from the OAuth provider contains a token to that effect.

Methods

POST /register/<authentication code>

Used by the client/authorisation seeker to register itself. The client is required to include a secret authentication code in the registration message.

The body of the POST request is a json in this form:

{
    'url': "The url that handles the forwarded OAuth response.",
    'ttl': "The optional time to live in seconds (defaults to 3600 seconds)",
    'secret': "A client-specific secret that should be used authenticate
    the forwarded request. If the request does not contain this secret,
    someone other than oauth_redirect has sent it."
}

Returns the token which needs to be passed by the OAuth provider:

{
    'token': "..."
}

(GET|POST) /redirect

The endpoint communicated to the OAuth provider through the redirect_uri. To authenticate the request coming from the OAuth provider must contain the token given by /register/<authentication code>.

Usually OAuth providers provide some kind of of value that may be passed from the client to the redirect_uri. This value can be used to carry the token back to the oauth_redirect server.

If there is no such value, the token may also be passed by url, using query paramters (i.e. https://oauth.seantis.ch/redirect?token=…).

Any value will do, a value in a json body, a formdata value or a query parameter.

If the redirect request is accepted it is proxied to the registered url. The result of the /redirect request is the result of the proxied url.

If the request was accepted, it is deleted.

Deployment

The server is implemented using aiohttp. It requires at least Python 3.5.

Though it might be possible to implement TLS support on the oauth_redirect we recommend that you put it behind a proper web proxy like nginx/apache.

To run the server run:

oauth-redirect --host localhost --port 8080 --database registered --auth <your custom auth code>

Run the Tests

Install tox and run it:

pip install tox
tox

Limit the tests to a specific python version:

tox -e py27

Conventions

Oauth_redirect follows PEP8 as close as possible. To test for it run:

tox -e pep8

Oauth_redirect uses Semantic Versioning

Build Status

Build Status

Coverage

Project Coverage

Latest PyPI Release

Latest PyPI Release

License

oauth_redirect is released under GPLv2

Changelog

0.2.0 (2017-05-24)

  • Adds the ability to define the HTTP method with which the redirect target should be called. [href]

  • Adds support for GET in addition to POST for the redirect view handler. [href]

0.1.0 (2017-05-23)

  • Initial Release. [href]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oauth_redirect-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

oauth_redirect-0.2.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file oauth_redirect-0.2.0.tar.gz.

File metadata

File hashes

Hashes for oauth_redirect-0.2.0.tar.gz
Algorithm Hash digest
SHA256 056fcfef46c0234d8a715424261620e79945c97b5a287422bcd77fbe63613589
MD5 27d9b53eef5a354a96bcb7ef83f11b00
BLAKE2b-256 4e05a2d5078f7a59201da67dd02dcdeeb71e1227a93ac4eed47dc00c20fb8be0

See more details on using hashes here.

File details

Details for the file oauth_redirect-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for oauth_redirect-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f76dd0a30905eb9a1049a13b1a42ef62d1e6aac52567d304fde9c111b3ce5f03
MD5 83cd8c056bc32559c19b34c5001071dd
BLAKE2b-256 788154c9c37870232e9f706b165e8c284f1b057bc2e37fdb736a28b7e69985a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page