Skip to main content

Librería para realizar login en Microsoft Entra ID como IdP

Project description

pysaml_idp

Autor : Alejandro Mejia Ayala

This library simplify SAML2 Login on Microsoft Entra ID (Azure AD) It requires:

  • A business application configured on Azure Panel
  • A unique Application Id
  • A valid callback Url configured in Business App
  • A valid login and logout Url addresses (from Business app configuration)

HOWTO

  • Create test subdir

        mkdir pysaml-idp-test & cd pysaml-idp-test
    
  • create a virtual environment

        python3 -m venv venv & source venv/bin/activate
    
  • Install requirenments

        pip install Flask pysaml-idp python-dotenv cryptography
    
  • Save variables on .env file

        APPLICATION_ID=<application_id> # from Azure Portal
        REDIRECT_URL=<Callback_URL> # Where login flow must return after Identification
        LOGIN_URL=<Login_Url>  # from Azure Portal
        LOGOUT_URL=<Logout_Url>  # from Azure Portal
    
  • app.py

        from flask import Flask, redirect, request, url_for, render_template
        import logging
        from pysaml_idp import SAML2
        from dotenv import load_dotenv
        import os
    
        load_dotenv()
    
        APPLICATION_ID = os.getenv('APPLICATION_ID')
        REDIRECT_URL = os.getenv('REDIRECT_URL')
        LOGIN_URL = os.getenv('LOGIN_URL')
        LOGOUT_URL = os.getenv('LOGOUT_URL')
    
        logging.basicConfig(level=logging.DEBUG)
        app = Flask(__name__)
        saml = SAML2(
            APPLICATION_ID,
            REDIRECT_URL,
            LOGIN_URL,
            LOGOUT_URL
        )
    
    
        @app.route('/')
        def hello_world():
            # Render the login template and pass the Azure AD login URL to the template
            return '<a href="/azure_login">Azure Idp Login</a>'
    
        @app.route('/azure_login')
        def azureLogin():
            login_url = saml.prepare_request()
            response = redirect(login_url, code=302)
            response.headers['Cache-Control'] = 'no-cache, no-store'
            response.headers['Pragma'] = 'no-cache'
            return response
    
        @app.route('/auth/redirect', methods=['GET','POST'])
        def saml_redirect():
            # Extract the SAML response from the request form data
            saml_response = request.form['SAMLResponse']
            claims = saml.extract_claims(saml_response)
            return claims
    
        if __name__ == '__main__':
            app.run(
                host='0.0.0.0',
                port="5000",
                debug=True,
                ssl_context='adhoc'
            )
    
  • run app

        $  export FLASK_APP=app
        $  export FLASK_ENV=development
        $  flask run
    
  • Open page on your preferred browser

      [https://127.0.0.1:5000/](https://127.0.0.1:5000/)
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysaml_idp-0.0.5.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysaml_idp-0.0.5-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pysaml_idp-0.0.5.tar.gz.

File metadata

  • Download URL: pysaml_idp-0.0.5.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pysaml_idp-0.0.5.tar.gz
Algorithm Hash digest
SHA256 fb200e4150df3098d9252b0b4e9d246dc0bad7e2ce01663a1dda93eabe56984a
MD5 712c43bc22f3e35ada7359006548fc0f
BLAKE2b-256 23e2201431d2877342a40aa62aa6e920f872ceb7acd1cc00241e89085b29c41a

See more details on using hashes here.

File details

Details for the file pysaml_idp-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pysaml_idp-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pysaml_idp-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a8dde2efd26d75f96a650434def51997a9f9d75d34c6955202de2ae1c49c21d1
MD5 6a54845820cac986e71f3893bb05b911
BLAKE2b-256 ad18ef9dc3e4e7e10b075244456a159a0e4f43e98726c007f70989a3c7da3ac9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page