GithubHelp home page GithubHelp logo

isabella232 / microsoft-authentication-extensions-for-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azuread/microsoft-authentication-extensions-for-python

0.0 0.0 0.0 158 KB

Microsoft Authentication Library extensions (MSAL EX) provides a persistence API that can save your data on disk, encrypted on Windows, macOS and Linux. Concurrent data access will be coordinated by a file lock mechanism.

License: MIT License

Python 97.25% Dockerfile 2.09% Shell 0.66%

microsoft-authentication-extensions-for-python's Introduction

Microsoft Authentication Extensions for Python

The Microsoft Authentication Extensions for Python offers secure mechanisms for client applications to perform cross-platform token cache serialization and persistence. It gives additional support to the Microsoft Authentication Library for Python (MSAL).

MSAL Python supports an in-memory cache by default and provides the SerializableTokenCache to perform cache serialization. You can read more about this in the MSAL Python documentation. Developers are required to implement their own cache persistance across multiple platforms and Microsoft Authentication Extensions makes this simpler.

The supported platforms are Windows, Mac and Linux.

  • Windows - DPAPI is used for encryption.
  • MAC - The MAC KeyChain is used.
  • Linux - LibSecret is used for encryption.

Note: It is recommended to use this library for cache persistance support for Public client applications such as Desktop apps only. In web applications, this may lead to scale and performance issues. Web applications are recommended to persist the cache in session. Take a look at this webapp sample.

Installation

You can find Microsoft Authentication Extensions for Python on Pypi.

  1. If you haven't already, install and/or upgrade the pip of your Python environment to a recent version. We tested with pip 18.1.
  2. Run pip install msal-extensions.

Versions

This library follows Semantic Versioning.

You can find the changes for each version under Releases.

Usage

The Microsoft Authentication Extensions library provides the PersistedTokenCache which accepts a platform-dependent persistence instance. This token cache can then be used to instantiate the PublicClientApplication in MSAL Python.

The token cache includes a file lock, and auto-reload behavior under the hood.

Here is an example of this pattern for multiple platforms (taken from the complete sample here):

def build_persistence(location, fallback_to_plaintext=False):
    """Build a suitable persistence instance based your current OS"""
    if sys.platform.startswith('win'):
        return FilePersistenceWithDataProtection(location)
    if sys.platform.startswith('darwin'):
        return KeychainPersistence(location, "my_service_name", "my_account_name")
    if sys.platform.startswith('linux'):
        try:
            return LibsecretPersistence(
                location,
                schema_name="my_schema_name",
                attributes={"my_attr1": "foo", "my_attr2": "bar"},
                )
        except:  # pylint: disable=bare-except
            if not fallback_to_plaintext:
                raise
            logging.exception("Encryption unavailable. Opting in to plain text.")
    return FilePersistence(location)

persistence = build_persistence("token_cache.bin")
print("Is this persistence encrypted?", persistence.is_encrypted)

cache = PersistedTokenCache(persistence)

Now you can use it in an MSAL application like this:

app = msal.PublicClientApplication("my_client_id", token_cache=cache)

Community Help and Support

We leverage Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!). Also browse existing issues to see if someone has had your question before.

We recommend you use the "msal" tag so we can see it! Here is the latest Q&A on Stack Overflow for MSAL: http://stackoverflow.com/questions/tagged/msal

Contributing

All code is licensed under the MIT license and we triage actively on GitHub.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

We value and adhere to the Microsoft Open Source Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

microsoft-authentication-extensions-for-python's People

Contributors

rayluo avatar marstr avatar abhidnya13 avatar microsoftopensource avatar navyasric avatar mparry avatar chlowell avatar greysteil avatar jhutchings1 avatar bluca avatar msftgits avatar rlrossiter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.