# UToken - Secure tokens
UToken (or Unhandleable Token) is a library designed to generate secure tokens with a guarantee of integrity for any type of project. With this project you can add payload and token lifetime.
To install UToken, use the `pip` package manager:
```
pip install utokeniz
```
# How to use
Here's a short tutorial on how to use UToken in a simple way.
## Creating a token
Let's start by creating a token, see the code below:
```python
from utoken import encode
# defining our key
KEY = 'secret-key'
# encoding
my_token = encode({'message': 'Hello World!'}, KEY)
print(my_token)
```
First we pass as a parameter to `utoken.encode()` the payload of the token, which must be a dictionary, then we pass the key that will be used to encode the token. After that we have our token in a string returned by the function.
### Define expiration time
We can add the token expiration time using the `expires_in` argument of the `utoken.encode` function. After the maximum time is reached the `ExpiredTokenError` exception will be thrown. In the example below, the token will expire in **5 minutes**:
```python
from utoken import encode
from datetime import timedelta
token = encode({'name': 'Maria'}, 'secret-key', expires_in=timedelta(minutes=5))
```
## Decoding a token
Now, let's decode a token. See the code below:
```python
import utoken
from datetime import timedelta
# defining our key
KEY = 'secret-key'
# create a token
token = utoken.encode({'name': 'Maria'}, KEY, expires_in=timedelta(minutes=5))
# decode a token
payload = utoken.decode(token, KEY)
print(payload)
```
Ready! Our token has been decoded. In `utoken.decode()` we pass as a parameter the token and the key used in the encoding, simple.
# License
```
Copyright © 2023 Jaedson Silva
BSD-3-Clause License
```
This project uses the `BSD-3-Clause` license. Please [see the license file](https://github.com/jaedsonpys/utoken/blob/master/LICENSE) to more informations.
Raw data
{
"_id": null,
"home_page": "https://github.com/jaedsonpys/utoken",
"name": "utokeniz",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "token,auth,json,web,login,secure",
"author": "Jaedson Silva",
"author_email": "imunknowuser@protonmail.com",
"download_url": "https://files.pythonhosted.org/packages/2d/86/bbb75e1ca9561db6fe88fd0d7e47a001dfd39b611181ccd8ff283d07271c/utokeniz-2.0.1.tar.gz",
"platform": null,
"description": "# UToken - Secure tokens\n\nUToken (or Unhandleable Token) is a library designed to generate secure tokens with a guarantee of integrity for any type of project. With this project you can add payload and token lifetime.\n\nTo install UToken, use the `pip` package manager:\n\n```\npip install utokeniz\n```\n\n# How to use\n\nHere's a short tutorial on how to use UToken in a simple way.\n\n## Creating a token\n\nLet's start by creating a token, see the code below:\n\n```python\nfrom utoken import encode\n\n# defining our key\nKEY = 'secret-key'\n\n# encoding\nmy_token = encode({'message': 'Hello World!'}, KEY)\nprint(my_token)\n```\n\nFirst we pass as a parameter to `utoken.encode()` the payload of the token, which must be a dictionary, then we pass the key that will be used to encode the token. After that we have our token in a string returned by the function.\n\n### Define expiration time\n\nWe can add the token expiration time using the `expires_in` argument of the `utoken.encode` function. After the maximum time is reached the `ExpiredTokenError` exception will be thrown. In the example below, the token will expire in **5 minutes**:\n\n```python\nfrom utoken import encode\nfrom datetime import timedelta\n\ntoken = encode({'name': 'Maria'}, 'secret-key', expires_in=timedelta(minutes=5))\n```\n\n## Decoding a token\n\nNow, let's decode a token. See the code below:\n\n```python\nimport utoken\nfrom datetime import timedelta\n\n# defining our key\nKEY = 'secret-key'\n\n# create a token\ntoken = utoken.encode({'name': 'Maria'}, KEY, expires_in=timedelta(minutes=5))\n\n# decode a token\npayload = utoken.decode(token, KEY)\nprint(payload)\n```\n\nReady! Our token has been decoded. In `utoken.decode()` we pass as a parameter the token and the key used in the encoding, simple.\n\n# License\n\n```\nCopyright \u00a9 2023 Jaedson Silva\nBSD-3-Clause License\n```\n\nThis project uses the `BSD-3-Clause` license. Please [see the license file](https://github.com/jaedsonpys/utoken/blob/master/LICENSE) to more informations.\n\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Create healthy and secure authentication tokens with UTokeniz.",
"version": "2.0.1",
"split_keywords": [
"token",
"auth",
"json",
"web",
"login",
"secure"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2d86bbb75e1ca9561db6fe88fd0d7e47a001dfd39b611181ccd8ff283d07271c",
"md5": "45f7e2b66ce7b2414b19fb99443e5058",
"sha256": "9d36647eadb8e3bc5317037ed21208040d4907eb6e331cd9fd100614941395c5"
},
"downloads": -1,
"filename": "utokeniz-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "45f7e2b66ce7b2414b19fb99443e5058",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4870,
"upload_time": "2023-03-25T16:38:38",
"upload_time_iso_8601": "2023-03-25T16:38:38.530731Z",
"url": "https://files.pythonhosted.org/packages/2d/86/bbb75e1ca9561db6fe88fd0d7e47a001dfd39b611181ccd8ff283d07271c/utokeniz-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-25 16:38:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "jaedsonpys",
"github_project": "utoken",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "utokeniz"
}