Giter Site home page Giter Site logo

python-basicauth's Introduction

python-basicauth

A dead simple HTTP basic auth encoder and decoder. Why? Because HTTP should be drop dead easy. That's why.

HTTP Basic Auth?!

Install

To install python-basicauth, simply run pip install basicauth and you'll get the latest version installed automatically.

Usage

To generate an encoded basic auth string:

>>> from basicauth import encode
>>> username, password = 'rdegges', 'omghax!!!'
>>> encoded_str = encode(username, password)
>>> print encoded_str
'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE='

To decode an encoded basic auth string:

>>> from basicauth import decode
>>> encoded_str = 'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE='  # From the example above.
>>> username, password = decode(encoded_str)
>>> print (username, password)
('rdegges', 'omghax!!!')

We can also decode the hash directly:

>>> from basicauth import decode
>>> encoded_str = 'cmRlZ2dlczpvbWdoYXglMjElMjElMjE='  # From the example above.
>>> username, password = decode(encoded_str)
>>> print (username, password)
('rdegges', 'omghax!!!')

And if there are errors:

>>> from basicauth import decode, DecodeError
>>> encoded_str = 'lol omg cmRlZ2dlczpvbWdoYXglMjElMjElMjE='  # Invalid hash.
>>> username, password = decode(encoded_str)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "basicauth/__init__.py", line 49, in decode
    raise DecodeError
basicauth.DecodeError

NOTE: The HTTP Basic Authentication spec doesn NOT allow you to include any colon characters (:) in the username field. Colons are allowed in the password field -- but that's it.

Tests

Build Status

Want to run the tests? No problem:

$ git clone git://github.com/rdegges/python-basicauth.git
$ cd python-basicauth
$ python setup.py develop
...
$ pip install -r requirements.txt  # Install test dependencies.
$ nosetests
.............
----------------------------------------------------------------------
Ran 13 tests in 0.166s

OK

python-basicauth's People

Contributors

bugov avatar ludovic-gasc avatar randalldegges-okta-2 avatar rdegges avatar rhelmer 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.