# ibmcloud-iam-python-client
[](https://pypi.org/project/ibmcloud-iam)
[](https://pepy.tech/project/ibmcloud-iam)
[](https://opensource.org/licenses/Apache-2.0)
[](https://app.travis-ci.com/mrodden/ibmcloud-iam-python-client)
This project is a collection of Python modules used for interacting with IBMCloud IAM API services.
Currently it includes support for:
- Requesting IAM tokens using an intelligent caching mechanism (`TokenManager`)
- Parsing IAM tokens and verifying their cryptographic signatures
- Checking user action authorizations for a service, given a Subject, Action and Resource set (`PDPClient`)
It is meant to be a lightweight client library that can be used in other projects, such as a service or other client.
Some things that will be added soon in the future:
- Caching authorization decisions from PDP
- Support for list a users Roles assigned from IAM policies
# Usage
## Install
`pip install ibmcloud_iam`
## Getting tokens with TokenManager
```python
import os
from ibmcloud_iam.token import TokenManager
tm = TokenManager(api_key=os.environ["IBMCLOUD_API_KEY"])
# whenever you need a token, just use 'tm.get_token()'
# get_token() will return a cached token if the token is not expired,
# or if expired or otherwise invalid, retrieve a new token for you
# gets a new token
print(tm.get_token())
# will return the same token as above, because of caching
print(tm.get_token())
```
## Parsing and Validating Tokens
```python
import os
import ibmcloud_iam.token
from ibmcloud_iam.token import TokenManager
tm = TokenManager(api_key=os.environ["IBMCLOUD_API_KEY"])
# validate_token will check the signature and parse and return the token claims
claims = ibmcloud_iam.token.validate_token(tm.get_token())
print(claims)
```
## PDP Authorizations
Please see [example.py](example.py) for an example on how to use the `PDPClient`
# Contributing
Feedback is appreciated in the form of bug reports, enhancement suggestions, testing, or pull requests/patches.
Pull requests and patches will be subject to review and will have to meet the standards of the project to be merged. We are willing to help with fixing issues and polishing if you are willing to be patient and understanding.
For bug reports, feature requests, or other support, please open a Github Issue in this repo.
If you are an IBMer and have access to the IBM Slack group, feel free to direct message me with questions at `@mrodden`.
Raw data
{
"_id": null,
"home_page": "https://github.com/mrodden/ibmcloud-iam-python-client",
"name": "ibmcloud-iam",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Mathew Odden",
"author_email": "mrodden@us.ibm.com",
"download_url": "https://files.pythonhosted.org/packages/15/69/35672b32d339e13a19c985790b2329168f862b4e7d8ec63809333870877d/ibmcloud-iam-0.1.7.tar.gz",
"platform": null,
"description": "# ibmcloud-iam-python-client\n\n[](https://pypi.org/project/ibmcloud-iam)\n[](https://pepy.tech/project/ibmcloud-iam)\n[](https://opensource.org/licenses/Apache-2.0)\n[](https://app.travis-ci.com/mrodden/ibmcloud-iam-python-client)\n\nThis project is a collection of Python modules used for interacting with IBMCloud IAM API services.\n\nCurrently it includes support for:\n\n - Requesting IAM tokens using an intelligent caching mechanism (`TokenManager`)\n - Parsing IAM tokens and verifying their cryptographic signatures\n - Checking user action authorizations for a service, given a Subject, Action and Resource set (`PDPClient`)\n\nIt is meant to be a lightweight client library that can be used in other projects, such as a service or other client.\n\nSome things that will be added soon in the future:\n\n - Caching authorization decisions from PDP\n - Support for list a users Roles assigned from IAM policies\n\n# Usage\n\n## Install\n\n`pip install ibmcloud_iam`\n\n## Getting tokens with TokenManager\n\n```python\nimport os\n\nfrom ibmcloud_iam.token import TokenManager\n\ntm = TokenManager(api_key=os.environ[\"IBMCLOUD_API_KEY\"])\n\n# whenever you need a token, just use 'tm.get_token()'\n# get_token() will return a cached token if the token is not expired,\n# or if expired or otherwise invalid, retrieve a new token for you\n\n# gets a new token\nprint(tm.get_token())\n\n# will return the same token as above, because of caching\nprint(tm.get_token())\n```\n\n## Parsing and Validating Tokens\n\n```python\nimport os\n\nimport ibmcloud_iam.token\nfrom ibmcloud_iam.token import TokenManager\n\ntm = TokenManager(api_key=os.environ[\"IBMCLOUD_API_KEY\"])\n\n# validate_token will check the signature and parse and return the token claims\nclaims = ibmcloud_iam.token.validate_token(tm.get_token())\n\nprint(claims)\n```\n\n## PDP Authorizations\n\nPlease see [example.py](example.py) for an example on how to use the `PDPClient`\n\n# Contributing\n\nFeedback is appreciated in the form of bug reports, enhancement suggestions, testing, or pull requests/patches.\n\nPull requests and patches will be subject to review and will have to meet the standards of the project to be merged. We are willing to help with fixing issues and polishing if you are willing to be patient and understanding.\n\nFor bug reports, feature requests, or other support, please open a Github Issue in this repo.\n\nIf you are an IBMer and have access to the IBM Slack group, feel free to direct message me with questions at `@mrodden`.\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A collection of Python modules used for interacting with IBMCloud IAM API services",
"version": "0.1.7",
"project_urls": {
"Homepage": "https://github.com/mrodden/ibmcloud-iam-python-client"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e9593a3863d9839a032e0c718a4b7d7dfbaa38bb4bf89abbb3d0fd99506e7252",
"md5": "24896ee23f07fe74b7b20e5f1ac855d8",
"sha256": "8b62aac1cc4a6cac0be1a20b2918cc48e4fffff5b5b0d5c07e71d31b8eeae75b"
},
"downloads": -1,
"filename": "ibmcloud_iam-0.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "24896ee23f07fe74b7b20e5f1ac855d8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 10293,
"upload_time": "2023-06-13T17:20:23",
"upload_time_iso_8601": "2023-06-13T17:20:23.521879Z",
"url": "https://files.pythonhosted.org/packages/e9/59/3a3863d9839a032e0c718a4b7d7dfbaa38bb4bf89abbb3d0fd99506e7252/ibmcloud_iam-0.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "156935672b32d339e13a19c985790b2329168f862b4e7d8ec63809333870877d",
"md5": "ae5c9811e9ef03bcfb1c7fc4c19c79a8",
"sha256": "8af82811e5d70cbd4b8745e7862d9fb68fb3dce3a0ed957be97cc3ea1272d961"
},
"downloads": -1,
"filename": "ibmcloud-iam-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "ae5c9811e9ef03bcfb1c7fc4c19c79a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8366,
"upload_time": "2023-06-13T17:20:24",
"upload_time_iso_8601": "2023-06-13T17:20:24.529737Z",
"url": "https://files.pythonhosted.org/packages/15/69/35672b32d339e13a19c985790b2329168f862b4e7d8ec63809333870877d/ibmcloud-iam-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-13 17:20:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mrodden",
"github_project": "ibmcloud-iam-python-client",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "ibmcloud-iam"
}