{ "info": { "author": "Usman Shahid", "author_email": "usman.shahid@intechww.com", "bugtrack_url": null, "classifiers": [], "description": "## Openidcpy\nA package that implements the Authorization Flow client for the OpenID Connect relying party. The package can be used to fetch OpenID Connect tokens using Authorization Flow and validate them using JWKS. The client has been implemented with KeyCloak as the OpenID Connect Authorization Provider.\n\n#### Usage\n\nThe only class of use is `OidcClient` which can be imported in code as:\n\n```python\nfrom openidcpy import OidcClient\n```\n\nYou'd need to initialize this client as follows:\n\n```python\ndiscovery_url = 'The .well_known discovery endpoint'\nclient_id = 'The client id assigned to the RP'\nclient_secret = 'The client secret assigned to RP if the client is private, otherwise None'\nclient = OidcClient(discovery_url=discovery_url, client_id=client_id, client_secret=client_secret)\n```\n\nThe client basically exposes 3 methods that, if called in sequence, complete the Authorization Flow. The first call is to create the authorization code url:\n\n```python\nresponse_type = 'code' # Always `code` for Authorization Flow\nredirect_uri = 'uri where the relying party is running'\nscopes = ['openid', 'email', 'profile'] # Array of requested scopes\nstate = 'Some random generated value that is returned in the redirect, prevents csrf'\nurl = client.create_auth_url(response_type=response_type, redirect_uri=redirect_uri, scopes=scopes, state=state)\n```\n\nYou'll need to redirect your application to the above url. The redirection will cause the auth server's login page to be displayed. Once the user logs in, the browser is redirected to the `redirect_uri` passed into the above call with an authorization code. You'll need to exchange the code with the JWT token as follows:\n\n```python\nurl = 'redirect_uri + query params, basically the endpoint on which the auth server redirected'\nredirect_uri = 'uri where the relying party is running'\nscopes = ['openid', 'email', 'profile'] # Array of requested scopes\nstate = 'Same value from the previous request'\ntokens = client.get_tokens_from_code(url=url, redirect_uri=redirect_uri, scopes=scopes, state=state)\n```\n\nNow, depending on the scopes you used the `tokens` dictionary can have either `access_token`, the `id_token` or both.\n\nThe next step is to validate these tokens, for which the client provides the following method:\n\n```python\nid_token = tokens['id_token']\nclaims = client.validate_jwt(id_token)\n```\nThe method validates the signature of the token, the audience (whether the token was intended for you) and the expiration of the token.\nThe `claims` dictionary will contain the decoded contents of the token. Based on the scopes you specified, it can contain the `email` or `preferred_username`.\n\n#### External Dependencies\n\n* requests (2.20.0)\n* python-jose (3.0.1)\n\n\n#### Contributions\n\nContributions are strongly encouraged, since this is just a basic implementation of the Authorization and there's a lot more to OpenId Connect that can be added here. I will try to add the rest whenever I find the time but if I can't, feel free to add it yourself.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/intech-iiot/openidcpy", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "openidcpy", "package_url": "https://pypi.org/project/openidcpy/", "platform": "", "project_url": "https://pypi.org/project/openidcpy/", "project_urls": { "Homepage": "https://github.com/intech-iiot/openidcpy" }, "release_url": "https://pypi.org/project/openidcpy/0.8/", "requires_dist": null, "requires_python": "", "summary": "A package that implements the Relying Party Authorization Code Flow for OpenId Connect", "version": "0.8" }, "last_serial": 5163745, "releases": { "0.6": [ { "comment_text": "", "digests": { "md5": "e7a48410070c1845ae0448ebc40a0dcb", "sha256": "6a675536c4997a45ecbc1977e1f0ccce4fb7c5dea4b8e7431be34913d389233d" }, "downloads": -1, "filename": "openidcpy-0.6.tar.gz", "has_sig": false, "md5_digest": "e7a48410070c1845ae0448ebc40a0dcb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3935, "upload_time": "2018-12-12T14:07:24", "url": "https://files.pythonhosted.org/packages/77/80/021e786dda93a0b0176e9a4a3404972b4ba05ad94612d4003bc9bcbfd3d0/openidcpy-0.6.tar.gz" } ], "0.7": [ { "comment_text": "", "digests": { "md5": "3d33c3e8aaedf38afb54fbcddc30d2f3", "sha256": "06e25bbf78d4fdbcd87272a6462f437b85d9afe755f86b5a9b4b06fddaa68864" }, "downloads": -1, "filename": "openidcpy-0.7.tar.gz", "has_sig": false, "md5_digest": "3d33c3e8aaedf38afb54fbcddc30d2f3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3971, "upload_time": "2019-04-11T06:18:23", "url": "https://files.pythonhosted.org/packages/fd/8e/1bf1f265134b73d6f7d6876c10b4857af9830eb48d9db99fdb5b73246aaf/openidcpy-0.7.tar.gz" } ], "0.8": [ { "comment_text": "", "digests": { "md5": "f10de671e234f1ab55706aaa5c886c3e", "sha256": "cd48c032071d34d8facb1eee55bafba31c5dbca85f07925006b2b45aa6eb8464" }, "downloads": -1, "filename": "openidcpy-0.8.tar.gz", "has_sig": false, "md5_digest": "f10de671e234f1ab55706aaa5c886c3e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3991, "upload_time": "2019-04-19T07:23:00", "url": "https://files.pythonhosted.org/packages/e7/e1/adeaf01aa4554f8ad3e147b039fd36cdefce778e58205eef5e23323be9ad/openidcpy-0.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f10de671e234f1ab55706aaa5c886c3e", "sha256": "cd48c032071d34d8facb1eee55bafba31c5dbca85f07925006b2b45aa6eb8464" }, "downloads": -1, "filename": "openidcpy-0.8.tar.gz", "has_sig": false, "md5_digest": "f10de671e234f1ab55706aaa5c886c3e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3991, "upload_time": "2019-04-19T07:23:00", "url": "https://files.pythonhosted.org/packages/e7/e1/adeaf01aa4554f8ad3e147b039fd36cdefce778e58205eef5e23323be9ad/openidcpy-0.8.tar.gz" } ] }