msal-requests-auth


Namemsal-requests-auth JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/corteva/msal-requests-auth
SummaryAuthentication using python requests and MSAL
upload_time2024-03-01 19:33:51
maintainer
docs_urlNone
authormsal_requests_auth Contributors
requires_python>=3.10
licenseBSD License
keywords msal requests
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ==================
msal-requests-auth
==================

Authentication using python requests and MSAL. This uses the MSAL cache
for repeated requests.

.. image:: https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square
    :alt: All Contributors
    :target: https://github.com/corteva/msal-requests-auth/blob/master/AUTHORS.rst

.. image:: https://img.shields.io/badge/License-BSD%203--Clause-yellow.svg
    :target: https://github.com/corteva/msal-requests-auth/blob/master/LICENSE

.. image:: https://img.shields.io/pypi/v/msal_requests_auth.svg
    :target: https://pypi.python.org/pypi/msal_requests_auth

.. image:: https://pepy.tech/badge/msal_requests_auth
    :target: https://pepy.tech/project/msal_requests_auth

.. image:: https://img.shields.io/conda/vn/conda-forge/msal_requests_auth.svg
    :target: https://anaconda.org/conda-forge/msal_requests_auth

.. image:: https://github.com/corteva/msal-requests-auth/workflows/Tests/badge.svg
    :target: https://github.com/corteva/msal-requests-auth/actions?query=workflow%3ATests

.. image:: https://codecov.io/gh/corteva/msal-requests-auth/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/corteva/msal-requests-auth

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
    :target: https://github.com/pre-commit/pre-commit

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/python/black


Bugs/Questions
--------------

- Report bugs/feature requests: https://github.com/corteva/msal-requests-auth/issues
- Ask questions: https://github.com/corteva/msal-requests-auth/discussions


Usage
-----

Compatible with:

- `requests <https://requests.readthedocs.io/en/latest/>`_
- `httpx <https://www.python-httpx.org/>`_


Device Code Flow
~~~~~~~~~~~~~~~~

.. note:: By default, `DeviceCodeAuth` copys the code to your clipboard and opens a webbrowser.
          To disable, either set `headless=True` when initializing `DeviceCodeAuth`
          or set the environment variable `MSAL_REQUESTS_AUTH_HEADLESS` to `true`.

- New in version 0.2.0: headless
- New in version 0.6.0: MSAL_REQUESTS_AUTH_HEADLESS environment variable
- New in version 0.7.0: KeyringTokenCache

.. code-block:: python

    import requests
    import msal
    from msal_requests_auth.auth import DeviceCodeAuth
    from msal_requests_auth.cache import KeyringTokenCache

    client_id = "<client ID from Azure AD>"
    tenant_id = "<tenant ID from Azure AD>"
    application_id = "<client ID of application you want to get a token for from Azure AD>"

    with KeyringTokenCache() as token_cache:
        app = msal.PublicClientApplication(
            client_id,
            authority=f"https://login.microsoftonline.com/{tenant_id}/",
            token_cache=token_cache,
        )
        auth = DeviceCodeAuth(
            client=app,
            scopes=[f"{application_id}/.default"],
        )
        response = requests.get(
            endpoint,
            auth=auth,
        )


Client Credentials Flow
~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    import requests
    import msal
    from msal_requests_auth.auth import ClientCredentialAuth

    client_id = "<client ID from Azure AD>"
    client_secret = "<client secret for client in Azure AD>"
    tenant_id = "<tenant ID from Azure AD>"
    application_id = "<client ID of application you want to get a token for from Azure AD>"
    app = msal.ConfidentialClientApplication(
        client_id,
        authority=(f"https://login.microsoftonline.com/{tenant_id}/"),
        client_credential=client_secret,
    )
    auth = ClientCredentialAuth(
        client=app,
        scopes=[f"{application_id}/.default"],
    )
    response = requests.get(
        endpoint,
        auth=auth,
    )


Installation
------------

To install msal-requests-auth, run this command in your terminal:

.. code-block:: console

    $ python -m pip install msal_requests_auth


If you use conda:

.. code-block:: console

    $ conda install -c conda-forge msal_requests_auth


Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/corteva/msal-requests-auth",
    "name": "msal-requests-auth",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "msal,requests",
    "author": "msal_requests_auth Contributors",
    "author_email": "alansnow21@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b1/d7/b2418f0f6dfedd2b18e359671f3ec3e88970cacd987dd871c8c2463de1a5/msal_requests_auth-0.8.0.tar.gz",
    "platform": "any",
    "description": "==================\nmsal-requests-auth\n==================\n\nAuthentication using python requests and MSAL. This uses the MSAL cache\nfor repeated requests.\n\n.. image:: https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square\n    :alt: All Contributors\n    :target: https://github.com/corteva/msal-requests-auth/blob/master/AUTHORS.rst\n\n.. image:: https://img.shields.io/badge/License-BSD%203--Clause-yellow.svg\n    :target: https://github.com/corteva/msal-requests-auth/blob/master/LICENSE\n\n.. image:: https://img.shields.io/pypi/v/msal_requests_auth.svg\n    :target: https://pypi.python.org/pypi/msal_requests_auth\n\n.. image:: https://pepy.tech/badge/msal_requests_auth\n    :target: https://pepy.tech/project/msal_requests_auth\n\n.. image:: https://img.shields.io/conda/vn/conda-forge/msal_requests_auth.svg\n    :target: https://anaconda.org/conda-forge/msal_requests_auth\n\n.. image:: https://github.com/corteva/msal-requests-auth/workflows/Tests/badge.svg\n    :target: https://github.com/corteva/msal-requests-auth/actions?query=workflow%3ATests\n\n.. image:: https://codecov.io/gh/corteva/msal-requests-auth/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/corteva/msal-requests-auth\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white\n    :target: https://github.com/pre-commit/pre-commit\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/python/black\n\n\nBugs/Questions\n--------------\n\n- Report bugs/feature requests: https://github.com/corteva/msal-requests-auth/issues\n- Ask questions: https://github.com/corteva/msal-requests-auth/discussions\n\n\nUsage\n-----\n\nCompatible with:\n\n- `requests <https://requests.readthedocs.io/en/latest/>`_\n- `httpx <https://www.python-httpx.org/>`_\n\n\nDevice Code Flow\n~~~~~~~~~~~~~~~~\n\n.. note:: By default, `DeviceCodeAuth` copys the code to your clipboard and opens a webbrowser.\n          To disable, either set `headless=True` when initializing `DeviceCodeAuth`\n          or set the environment variable `MSAL_REQUESTS_AUTH_HEADLESS` to `true`.\n\n- New in version 0.2.0: headless\n- New in version 0.6.0: MSAL_REQUESTS_AUTH_HEADLESS environment variable\n- New in version 0.7.0: KeyringTokenCache\n\n.. code-block:: python\n\n    import requests\n    import msal\n    from msal_requests_auth.auth import DeviceCodeAuth\n    from msal_requests_auth.cache import KeyringTokenCache\n\n    client_id = \"<client ID from Azure AD>\"\n    tenant_id = \"<tenant ID from Azure AD>\"\n    application_id = \"<client ID of application you want to get a token for from Azure AD>\"\n\n    with KeyringTokenCache() as token_cache:\n        app = msal.PublicClientApplication(\n            client_id,\n            authority=f\"https://login.microsoftonline.com/{tenant_id}/\",\n            token_cache=token_cache,\n        )\n        auth = DeviceCodeAuth(\n            client=app,\n            scopes=[f\"{application_id}/.default\"],\n        )\n        response = requests.get(\n            endpoint,\n            auth=auth,\n        )\n\n\nClient Credentials Flow\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    import requests\n    import msal\n    from msal_requests_auth.auth import ClientCredentialAuth\n\n    client_id = \"<client ID from Azure AD>\"\n    client_secret = \"<client secret for client in Azure AD>\"\n    tenant_id = \"<tenant ID from Azure AD>\"\n    application_id = \"<client ID of application you want to get a token for from Azure AD>\"\n    app = msal.ConfidentialClientApplication(\n        client_id,\n        authority=(f\"https://login.microsoftonline.com/{tenant_id}/\"),\n        client_credential=client_secret,\n    )\n    auth = ClientCredentialAuth(\n        client=app,\n        scopes=[f\"{application_id}/.default\"],\n    )\n    response = requests.get(\n        endpoint,\n        auth=auth,\n    )\n\n\nInstallation\n------------\n\nTo install msal-requests-auth, run this command in your terminal:\n\n.. code-block:: console\n\n    $ python -m pip install msal_requests_auth\n\n\nIf you use conda:\n\n.. code-block:: console\n\n    $ conda install -c conda-forge msal_requests_auth\n\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n",
    "bugtrack_url": null,
    "license": "BSD License",
    "summary": "Authentication using python requests and MSAL",
    "version": "0.8.0",
    "project_urls": {
        "Download": "http://python.org/pypi/msal-requests-auth",
        "Homepage": "https://github.com/corteva/msal-requests-auth"
    },
    "split_keywords": [
        "msal",
        "requests"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46ae570dd518d636c5940fb70cf209faf5478128de34f990bebaa080eeac5e26",
                "md5": "edd011eb71073e314ff3afc9beccdc87",
                "sha256": "e89c812d390a1c3206705d2d452aa7eaa3a21225398b3ea227829c3cf1c1c405"
            },
            "downloads": -1,
            "filename": "msal_requests_auth-0.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "edd011eb71073e314ff3afc9beccdc87",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9464,
            "upload_time": "2024-03-01T19:33:49",
            "upload_time_iso_8601": "2024-03-01T19:33:49.663688Z",
            "url": "https://files.pythonhosted.org/packages/46/ae/570dd518d636c5940fb70cf209faf5478128de34f990bebaa080eeac5e26/msal_requests_auth-0.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b1d7b2418f0f6dfedd2b18e359671f3ec3e88970cacd987dd871c8c2463de1a5",
                "md5": "d7993155d07da37432597be0fe68f546",
                "sha256": "4fadd1b7021173fc18930070c7164da055b1e59bdf78e199c02fa9f4aa147ab3"
            },
            "downloads": -1,
            "filename": "msal_requests_auth-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d7993155d07da37432597be0fe68f546",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14263,
            "upload_time": "2024-03-01T19:33:51",
            "upload_time_iso_8601": "2024-03-01T19:33:51.291493Z",
            "url": "https://files.pythonhosted.org/packages/b1/d7/b2418f0f6dfedd2b18e359671f3ec3e88970cacd987dd871c8c2463de1a5/msal_requests_auth-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-01 19:33:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "corteva",
    "github_project": "msal-requests-auth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "msal-requests-auth"
}
        
Elapsed time: 0.20408s