Giter Site home page Giter Site logo

iamnicoj / aad-multitenant-apis-managed-identities Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.49 MB

This project includes a working example on how to setup and run a service to service authentication using OAuth v2 client credential flow, on a multi-tenant set up without sharing client secrets, but with using Managed Identities in Azure

License: MIT License

HCL 87.44% C# 12.56%

aad-multitenant-apis-managed-identities's Introduction

AAD-Multitenant-APIs-w-Managed-Identities

This project includes a working example on how to setup and run a service to service authentication using OAuth v2 client credential flow, on a multi-tenant set up without the need to share any client secret, but using Managed Identities in Azure.

Content

  • Preconditions
  • Multitenant SetUp Client Secret model Maganed identity model ** Create main App in Tenant A ** Authorized main App in Tenant B
  • Terraform Deployments enabling MI
  • Java Code to get MI Access token

Apps

Basic API that validates JWT

Basic asp.net core API template that uses Microsoft.AspNetCore.Authentication.JwtBearer library to validate JWT tokens. URL https://nicojkwebapi2.azurewebsites.net/weatherforecast

Azure Function calling the API that enables Managed Identity to get the access token

AAD Tenants

Main Tenant - API Multitenant APP

  1. Run the main_aad_tenant_app.tf within the main_terraform folder, to provision the main app registration in the AAD tenant. Make sure you perform a terraform init and an az login to the desired ad tenant. Because of terraform limitations hashicorp/terraform#23966 you will have to first perform a terraform apply before assigning the mainAppId and app_role_id variable names and the run a second terraform apply to have terraform assigning the correct required_resource_access profiles

  2. After the app has been registered, have the tenant admin manually give admin consent on the custom role in the azure portal Admin Consent

Second Tenant - Consumer API Tenant

It includes a Service Principal that's linked to the Main API app registration. It does not have a client secret. It includes another Service Principal automatically created to be used by the Azure Function deployed in the Azure subscription linked to the this consumer API Tenant

  1. Invoke this URL to register and trust the Multitenant App in the second tenant https://login.microsoftonline.com/{secondTenandID}/v2.0/adminconsent?client_id={APP_IP}&redirect_uri={redirect_URI}&scope=openid+profile

  2. Then submit another request with the actual Multitenant API scope using this format https://login.microsoftonline.com/{secondTenandID}/v2.0/adminconsent?client_id={APP_IP}&redirect_uri={redirect_URI}&scope={APP ID}/.default, this way the APP will be register with the whole scope of permissions from the main tenant in the secondary tenant.

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.