basicauth


Namebasicauth JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/rdegges/python-basicauth
SummaryAn incredibly simple HTTP basic auth implementation.
upload_time2022-12-23 02:54:13
maintainer
docs_urlNone
authorRandall Degges
requires_python
licenseUNLICENSE
keywords security basicauth http
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python-basicauth

[![Build Status](https://github.com/rdegges/python-basicauth/actions/workflows/test.yml/badge.svg)](https://github.com/rdegges/python-basicauth/actions)

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


## 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:

``` python
>>> 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:

``` python
>>> 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 encoded string directly:

``` python
>>> 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:

``` python
>>> from basicauth import decode, DecodeError
>>> encoded_str = 'lol omg cmRlZ2dlczpvbWdoYXglMjElMjElMjE='  # Invalid encoded string.
>>> 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](http://www.ietf.org/rfc/rfc2617.txt)
does **NOT** allow you to include any colon characters (`:`) in the username
field. Colons are allowed in the password field -- but that's it.


## Tests

Want to run the tests? No problem:

``` bash
$ git clone https://github.com/rdegges/python-basicauth.git
$ cd python-basicauth
$ pip install -e .
...
$ python -m unittest
..............
----------------------------------------------------------------------
Ran 14 tests in 0.103s

OK
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rdegges/python-basicauth",
    "name": "basicauth",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "security,basicauth,http",
    "author": "Randall Degges",
    "author_email": "r@rdegges.com",
    "download_url": "https://files.pythonhosted.org/packages/3e/38/561378a529cc63303bb1e02c44801dda277b634169cbb1b86c0a68431e5f/basicauth-1.0.0.tar.gz",
    "platform": null,
    "description": "# python-basicauth\n\n[![Build Status](https://github.com/rdegges/python-basicauth/actions/workflows/test.yml/badge.svg)](https://github.com/rdegges/python-basicauth/actions)\n\nA dead simple HTTP basic auth encoder and decoder. Why? Because HTTP should be\ndrop dead easy... That's why.\n\n\n## Install\n\nTo install ``python-basicauth``, simply run ``pip install basicauth`` and\nyou'll get the latest version installed automatically.\n\n\n## Usage\n\nTo generate an encoded basic auth string:\n\n``` python\n>>> from basicauth import encode\n>>> username, password = 'rdegges', 'omghax!!!'\n>>> encoded_str = encode(username, password)\n>>> print encoded_str\n'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE='\n```\n\nTo decode an encoded basic auth string:\n\n``` python\n>>> from basicauth import decode\n>>> encoded_str = 'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE='  # From the example above.\n>>> username, password = decode(encoded_str)\n>>> print (username, password)\n('rdegges', 'omghax!!!')\n```\n\nWe can also decode the encoded string directly:\n\n``` python\n>>> from basicauth import decode\n>>> encoded_str = 'cmRlZ2dlczpvbWdoYXglMjElMjElMjE='  # From the example above.\n>>> username, password = decode(encoded_str)\n>>> print (username, password)\n('rdegges', 'omghax!!!')\n```\n\nAnd if there are errors:\n\n``` python\n>>> from basicauth import decode, DecodeError\n>>> encoded_str = 'lol omg cmRlZ2dlczpvbWdoYXglMjElMjElMjE='  # Invalid encoded string.\n>>> username, password = decode(encoded_str)\nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\n  File \"basicauth/__init__.py\", line 49, in decode\n    raise DecodeError\nbasicauth.DecodeError\n```\n\n**NOTE**: The [HTTP Basic Authentication spec](http://www.ietf.org/rfc/rfc2617.txt)\ndoes **NOT** allow you to include any colon characters (`:`) in the username\nfield. Colons are allowed in the password field -- but that's it.\n\n\n## Tests\n\nWant to run the tests? No problem:\n\n``` bash\n$ git clone https://github.com/rdegges/python-basicauth.git\n$ cd python-basicauth\n$ pip install -e .\n...\n$ python -m unittest\n..............\n----------------------------------------------------------------------\nRan 14 tests in 0.103s\n\nOK\n```\n",
    "bugtrack_url": null,
    "license": "UNLICENSE",
    "summary": "An incredibly simple HTTP basic auth implementation.",
    "version": "1.0.0",
    "split_keywords": [
        "security",
        "basicauth",
        "http"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "88f12023baa7eeed3ac2868d5c65f3ae",
                "sha256": "5e6eb3deb883b1fce552e25b6a97083e1b5ab28771b3d7c2b76c5b6ae1cc4da7"
            },
            "downloads": -1,
            "filename": "basicauth-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "88f12023baa7eeed3ac2868d5c65f3ae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3753,
            "upload_time": "2022-12-23T02:54:11",
            "upload_time_iso_8601": "2022-12-23T02:54:11.738972Z",
            "url": "https://files.pythonhosted.org/packages/52/b5/5bb9477a6a0b4fe88d2849858e150f07481200d5b4b4c789a39bd567e5b4/basicauth-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "4a3ff156c8fc4d8abe413520cc4f0c84",
                "sha256": "e4739db0a8bd146702c3501afda172e66b51ebafc15ee65adbecb86b9ee0d51b"
            },
            "downloads": -1,
            "filename": "basicauth-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4a3ff156c8fc4d8abe413520cc4f0c84",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3556,
            "upload_time": "2022-12-23T02:54:13",
            "upload_time_iso_8601": "2022-12-23T02:54:13.015724Z",
            "url": "https://files.pythonhosted.org/packages/3e/38/561378a529cc63303bb1e02c44801dda277b634169cbb1b86c0a68431e5f/basicauth-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-23 02:54:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "rdegges",
    "github_project": "python-basicauth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "basicauth"
}
        
Elapsed time: 0.02700s