GithubHelp home page GithubHelp logo

azure-vms-rest-api-demo's Introduction

Azure VM REST API DEMO

This code demonstrates how a Web application can authenticate users and call a downstream API using the signed in user's token

This code is based on: https://github.com/Azure-Samples/ms-identity-python-webapp

The demo uses the Microsoft Identity Platform and the Microsoft Authentication Library(MSAL) for Python to manage user authentication.

To call azure management APIs, the app obtains an access token for the user with the scope "https://management.azure.com/user_impersonation". This allows the app to impersonate the user in the downstream API requests to Azure Management API.

 token = auth.get_token_for_user(["https://management.azure.com/user_impersonation"])

Instructions

  1. Create an app registration in Azure AD and give it the API permission user_impersonation for management.azure.com

  2. Create a client secret in the app registration.

  3. Clone the repository or download it to your local environment

    PS > git clone [email protected]:aminsrc/azure-vms-rest-api-demo.git
    
  4. In the root folder of the repository, create a python virtual environment, activate it, and pip install requirements

    PS > cd azure-vms-rest-api-demo
    PS > virtualenv.exe venv
    PS > .\venv\Scripts\activate
    PS > pip install -r requirements.txt
    
  5. Set the following environment variables:

    PS > $env:CLIENT_ID=<Your App registration Client ID>
    PS > $env:CLIENT_SECRET=<Your app registration client secret>
    PS > $env:SUBSCRIPTION_ID=<Your subscription>
    PS > $env:TENANT_ID=<Your tenant-ID>
    
  6. Run the app

    PS > python.exe .\app.py
    

azure-vms-rest-api-demo's People

Contributors

modamin avatar

Watchers

 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.