{"id":19601255,"url":"https://github.com/refinitiv/bottle-oauthlib","last_synced_at":"2025-04-27T16:32:33.092Z","repository":{"id":49037344,"uuid":"114389493","full_name":"Refinitiv/bottle-oauthlib","owner":"Refinitiv","description":"Bottle adapter for OAuthlib framework (OAuth2.0)","archived":false,"fork":false,"pushed_at":"2023-08-23T12:33:49.000Z","size":234,"stargazers_count":46,"open_issues_count":2,"forks_count":15,"subscribers_count":90,"default_branch":"master","last_synced_at":"2025-04-22T21:04:46.261Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Refinitiv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-15T16:18:25.000Z","updated_at":"2025-04-17T16:11:14.000Z","dependencies_parsed_at":"2024-11-11T09:17:46.860Z","dependency_job_id":"23694f09-1ae3-49c3-b86e-e0d6c19619a3","html_url":"https://github.com/Refinitiv/bottle-oauthlib","commit_stats":null,"previous_names":["thomsonreuters/bottle-oauthlib"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refinitiv%2Fbottle-oauthlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refinitiv%2Fbottle-oauthlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refinitiv%2Fbottle-oauthlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Refinitiv%2Fbottle-oauthlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Refinitiv","download_url":"https://codeload.github.com/Refinitiv/bottle-oauthlib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251171746,"owners_count":21547155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T09:17:43.913Z","updated_at":"2025-04-27T16:32:33.085Z","avatar_url":"https://github.com/Refinitiv.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bottle-oauthlib\n\n[![Build](https://github.com/refinitiv/bottle-oauthlib/actions/workflows/python.yml/badge.svg)](https://github.com/Refinitiv/bottle-oauthlib/actions)\n[![Coverage Status](https://coveralls.io/repos/github/Refinitiv/bottle-oauthlib/badge.svg?branch=master)](https://coveralls.io/github/Refinitiv/bottle-oauthlib?branch=master)\n[![pip install bottle-oauthlib](https://img.shields.io/pypi/v/bottle-oauthlib.svg)](https://pypi.python.org/pypi/bottle-oauthlib)\n\n## Context\n\nInterested to implement your own OAuth2.0 or OpenID Connect Provider in python ? You're at the right place.\n\nCombine the excellent https://github.com/oauthlib/oauthlib framework and the micro-framework https://github.com/bottlepy/bottle to provide OAuth2.0 authorization in only a couple of minutes.\n\nOAuth2.0 basic knowledge is more than welcomed ! However, for novices users, as a rule of thumb, you must understand the OAuth2.0 is a delegation protocol. Basically, it delegates authorization (through scopes) to an application (client).\n\nNote that you can implement only the delegation part or the authorization server or an application, or all combined. That's your choice.\n\nFor more information about OAuth2.0 fundamentals, check https://oauth.net/2/\n\n## Quick start\n\nDefine rules into a oauthlib.RequestValidator class. See [oauthlib#implement-a-validator](https://oauthlib.readthedocs.io/en/latest/oauth2/server.html#implement-a-validator):\n```python\nclass MyOAuth2_Validator(oauth2.RequestValidator):\n    def authenticate_client_id(self, client_id, ..):\n        \"\"\"validate client_id\"\"\"\n\n    def validate_user(self, username, password, client, ..):\n        \"\"\"validate username \u0026 password\"\"\"\n\n    def validate_scopes(self, client_id, scopes, ..):\n        \"\"\"validate scope against the client\"\"\"\n\n    (..)\n```\n\nLink it to a preconfigured `oauthlib` Server, then to a `bottle` app: \n\n```python\nimport bottle\nfrom bottle_oauthlib.oauth2 import BottleOAuth2\nfrom oauthlib import oauth2\n\nvalidator = MyOAuth2_Validator()\nserver = oauth2.Server(validator)\n\napp = bottle.Bottle()\napp.auth = BottleOAuth2(app)\napp.auth.initialize(server)\n```\n\nFinally, declare `bottle` endpoints to request token:\n```python\n@app.post('/token')\n@app.auth.create_token_response()\ndef token():\n    \"\"\"an empty controller is enough for most cases\"\"\"\n```\n\nIn addition, you can declare a _resource_ endpoint which verify a token and its optional scopes:\n```python\n@app.get('/calendar')\n@app.auth.verify_request(scopes=['calendar'])\ndef access_calendar():\n    return \"Welcome {}, you have permissioned {} to use your calendar\".format(\n        bottle.request.oauth[\"user\"],\n        bottle.request.oauth[\"client\"].client_id\n    )\n```\n\nSee the full example in our code source at [quickstart.py](https://github.com/Refinitiv/bottle-oauthlib/blob/master/tests/examples/quickstart.py). Don't hesitate to copy it for your own project and its unit tests at [test_quickstart.py](https://github.com/Refinitiv/bottle-oauthlib/blob/master/tests/test_quickstart.py) to be confident when you upgrade.\n\nIf you are not interested in doing a full Provider but only a Resource Server, just use the quickstart example for OAuth2.0 Resource Server. You can either use an Introspection Endpoint or decode JWT and validate yourself the Bearer tokens. Start with the [quickstart_resourceserver.py](https://github.com/Refinitiv/bottle-oauthlib/blob/master/tests/examples/quickstart_resourceserver.py) and its unit tests at [test_quickstart_resourceserver.py](https://github.com/Refinitiv/bottle-oauthlib/blob/master/tests/test_quickstart_resourceserver.py).\n\n## Help \u0026 support\n\nFeel free to ask question or support by opening a Github issue https://github.com/Refinitiv/bottle-oauthlib/issues.\n\n\n## Contribution\n\nDon't hesitate to propose PR, they are more than welcomed. Please, be sure you're compliant with our [Contribution guide](https://github.com/Refinitiv/bottle-oauthlib/blob/master/docs/CONTRIBUTING.md).\n\n\n## Copyright\n\nThis document is licensed under BSD-3-Clause license. See LICENSE for details.\n\nThe code was opened by (c) Refinitiv (previously Thomson Reuters).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefinitiv%2Fbottle-oauthlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frefinitiv%2Fbottle-oauthlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefinitiv%2Fbottle-oauthlib/lists"}