How to use Logic App with Azure Active Directory Authorization Policies

Published Dec 15 2020 01:42 AM 3,016 Views

 

Mobarqaw_1-1607955738591.png

 

In this article, I will demonstrate how to call a logic app with the Aouth2 approach

The problem that I going to solve is to provide a gatekeeper page that will not download files from the Storage account unless the user is authenticated.

 

I will utilize a static web site on the storage account to host small HTTP pages and javascripts

Spoiler
the Idea of a Static site is to provide simple hosting and the same solution can be hosted on the app service as well 

the web page will be responsible to obtain the Bearer token when the user Sign-in

then it will use this Token to pass it to the logic app  

 

Spoiler

Create website.

You can create the static by following the Host a static website in Azure Storage | Microsoft Docs

Mobarqaw_2-1607955738597.png

 

 

Create the Active Directory application

 

I have followed the article https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-javascript

Register your application
  1. Sign in to the Azure portal.
  2. If you have access to multiple tenants, use the Directory + subscription filter Mobarqaw_3-1607955738600.png

     

     in the top menu to select the tenant in which you want to register an application.
  3. Search for and select Azure Active Directory.
  4. Under Manage, select App registrations > New registration.
  5. Enter a Name for your application. Users of your app might see this name, and you can change it later.
  6. Under Supported account types, select Accounts in any organizational directory and personal Microsoft accounts.
  7. Select Register. On the app Overview page, note the Application (client) ID value for later use.
  8. Under Platform Configurations, select Add a platform. A panel opens on the left. There, select the Web Applications region.
  9. Still on the left, set the Redirect URI value to [the static website URL] Then, select Access Token and ID Token.
  10. Select Configure.

 

1.2.2        Build the HTML page with msal.js

Create HTML with the below content

 

 

 

 

 

!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <title>Demo for using Logic app using Azure Active Directory Authorization Policies </title>
  <link rel="SHORTCUT ICON" href="./favicon.svg" type="image/x-icon">

  <!-- msal.min.js can be used in the place of msal.js; included msal.js to make debug easy -->
  <script type="text/javascript" src="https://alcdn.msauth.net/lib/1.4.4/js/msal.js"
    integrity="sha384-fTmwCjhRA6zShZq8Ow5ZkbWwmgp8En46qW6yWpNEkp37MkV50I/V2wjzlEkQ8eWD"
    crossorigin="anonymous"></script>

  <!-- msal.js with a fallback to backup CDN -->
  <script type="text/javascript">
    if (typeof Msal === 'undefined') document.write(unescape("%3Cscript src='https://alcdn.msftauth.net/lib/1.4.4/js/msal.js' type='text/javascript' %3E%3C/script%3E"));
  </script>

  <!-- adding Bootstrap 4 for UI components  -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand" href="/">Storage account Gate keeper using logic app </a>
    <div class="btn-group ml-auto dropleft">
      <button type="button" id="signIn" class="btn btn-secondary" onclick="signIn()">Sign In</button>
      <button type="button" id="signOut" class="btn btn-success d-none" onclick="signOut()">Sign Out</button>
    </div>
  </nav>
  <br>
  <h5 class="card-header text-center">this is a demo only site </h5>
  <br>
  <div class="row" style="margin:auto">
    <div id="card-div" class="col-md-3 d-none">
      <div class="card text-center">
        <div class="card-body">
          <h5 class="card-title" id="welcomeMessage">Please sign-in to see your profile and read your mails</h5>
          <div id="profile-div"></div>
          <br>
          <br>
          <button class="btn btn-primary" id="seeProfile" onclick="downloadFile()">Download File</button>
          <br>
        </div>
      </div>
    </div>
    <br>
    <br>
    <div class="col-md-4">
      <div class="list-group" id="list-tab" role="tablist">
      </div>
    </div>
    <div class="col-md-5">
      <div class="tab-content" id="nav-tabContent">
      </div>
    </div>
  </div>
  <br>
  <br>
  <!-- importing bootstrap.js and supporting js libraries -->
  <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
    integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
    crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
    integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
    crossorigin="anonymous"></script>
  <!-- importing app scripts (load order is important) -->
  <script type="text/javascript" src="./authConfig.js"></script>
  <script type="text/javascript" src="./ui.js"></script>
  <script type="text/javascript" src="./authPopup.js"></script>

</body>

</html>

 

 

 

 

 

 

 

Create file authPopup.js

 

 

 

 

 

// Create the main myMSALObj instance
// configuration parameters are located at authConfig.js
const myMSALObj = new Msal.UserAgentApplication(msalConfig);
var Bearer = ''
let searchParams = new URLSearchParams(window.location.search)
let fileParam = searchParams.get('file')
function signIn() {
  myMSALObj.loginPopup(loginRequest)
    .then(loginResponse => {
      console.log("id_token acquired at: " + new Date().toString());
      console.log(loginResponse);

      if (myMSALObj.getAccount()) {
        Bearer = loginResponse.idToken.rawIdToken;
        showWelcomeMessage(myMSALObj.getAccount());
      }
    }).catch(error => {
      console.log(error);
    });
}

function signOut() {
  myMSALObj.logout();
}

//endpoint, token, callback
function downloadFile() {

  const headers = new Headers();
  const bearer = `Bearer ${Bearer}`;

  headers.append("Authorization", bearer);
  headers.append("FileName", fileParam);

  const options = {
    method: "post",
    headers: headers
  };
  fetch(logicAppUrl, options)
    .then(resp => resp.blob())
    .then(blob => {
      const url = window.URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.style.display = 'none';
      a.href = url;
      // the filename you want
      a.download = fileParam;
      document.body.appendChild(a);
      a.click();
      window.URL.revokeObjectURL(url);
      alert('your file has downloaded!'); // or you know, something with better UX...
    })
    .catch(error => console.log(error))
}

 

 

 

 

authConfig.js

 

 

 

 

 
// Config object to be passed to Msal on creation.
// For a full list of msal.js configuration parameters, 
// visit https://azuread.github.io/microsoft-authentication-library-for-js/docs/msal/modules/_authenticationparameters_.html
const msalConfig = {
  auth: {
    clientId: "7ebe8908-7acd-4e20-b1f4-24715b364cf0",
    authority: "https://login.microsoftonline.com/common",
    redirectUri: "https://largfile.z6.web.core.windows.net",
  },
  cache: {
    cacheLocation: "sessionStorage", // This configures where your cache will be stored
    storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge
  }
};  
  
// Add here the scopes to request when obtaining an access token for MS Graph API
// for more, visit https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-core/docs/scopes.md
const loginRequest = {
  scopes: ["openid", "profile", "User.Read"]
};

const logicAppUrl='https://prod-39.eastus.logic.azure.com:443/workflows/92083fac9d2c4805b153907db6976f86/triggers/manual/paths/invoke?api-version=2016-10-01'

 

 

 

 

Creating the logic app

 

The logic app will receive the request using HTTP and will pass the file name to the storage account action

Mobarqaw_4-1607955738602.png

 

 

1.3.1        Enable logic app Azure Active Directory Authorization Policies

Make the issuer https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0  The GUID that indicates that the user is a consumer user from a Microsoft account is 9188040d-6c67-4c5b-b112-36a304b66dad for information at

https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens

 

 

Mobarqaw_5-1607955738604.png

 

More information on Secure access and data - Azure Logic Apps | Microsoft Docs

 

the HTML and JavaScript attached 

%3CLINGO-SUB%20id%3D%22lingo-sub-1985428%22%20slang%3D%22en-US%22%3EHow%20to%20use%20Logic%20App%20with%20Azure%20Active%20Directory%20Authorization%20Policies%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1985428%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Mobarqaw_1-1607955738591.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F240170iFB566726CA3DC42C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Mobarqaw_1-1607955738591.png%22%20alt%3D%22Mobarqaw_1-1607955738591.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20article%2C%20I%20will%20demonstrate%20how%20to%20call%20a%20logic%20app%20with%20the%20Aouth2%20approach%3C%2FP%3E%0A%3CP%3EThe%20problem%20that%20I%20going%20to%20solve%20is%20to%20provide%20a%20gatekeeper%20page%20that%20will%20not%20download%20files%20from%20the%20Storage%20account%20unless%20the%20user%20is%20authenticated.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20will%20utilize%20a%20%3CSTRONG%3Estatic%20web%20site%3C%2FSTRONG%3E%20on%20the%20storage%20account%20to%20host%20small%20HTTP%20pages%20and%20javascripts%3C%2FP%3E%0A%3CDIV%20class%3D%22lia-spoiler-container%22%3E%3CA%20class%3D%22lia-spoiler-link%22%20href%3D%22%23%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESpoiler%3C%2FA%3E%3CNOSCRIPT%3E(Highlight%20to%20read)%3C%2FNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-border%22%3E%3CDIV%20class%3D%22lia-spoiler-content%22%3Ethe%20Idea%20of%20a%20Static%20site%20is%20to%20provide%20simple%20hosting%20and%20the%20same%20solution%20can%20be%20hosted%20on%20the%20app%20service%20as%20well%26nbsp%3B%3C%2FDIV%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-noscript-container%22%3E%3CDIV%20class%3D%22lia-spoiler-noscript-content%22%3Ethe%20Idea%20of%20a%20Static%20site%20is%20to%20provide%20simple%20hosting%20and%20the%20same%20solution%20can%20be%20hosted%20on%20the%20app%20service%20as%20well%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FNOSCRIPT%3E%3C%2FDIV%3E%3C%2FDIV%3E%0A%3CP%3Ethe%20web%20page%20will%20be%20responsible%20to%20obtain%20the%20Bearer%20token%20when%20the%20user%20Sign-in%3C%2FP%3E%0A%3CP%3Ethen%20it%20will%20use%20this%20Token%20to%20pass%20it%20to%20the%20logic%20app%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20class%3D%22lia-spoiler-container%22%3E%3CA%20class%3D%22lia-spoiler-link%22%20href%3D%22%23%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESpoiler%3C%2FA%3E%3CNOSCRIPT%3E(Highlight%20to%20read)%3C%2FNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-border%22%3E%3CDIV%20class%3D%22lia-spoiler-content%22%3EI%20have%20used%20the%20library%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzureAD%2Fmicrosoft-authentication-library-for-js%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGitHub%20-%20AzureAD%2Fmicrosoft-authentication-library-for-js%3A%20Microsoft%20Authentication%20Library%20(MSAL)%20for%20JS%3C%2FA%3E%26nbsp%3Bto%20do%20the%20authentication%26nbsp%3B%3C%2FDIV%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-noscript-container%22%3E%3CDIV%20class%3D%22lia-spoiler-noscript-content%22%3EI%20have%20used%20the%20library%26nbsp%3BGitHub%20-%20AzureAD%2Fmicrosoft-authentication-library-for-js%3A%20Microsoft%20Authentication%20Library%20(MSAL)%20for%20JS%26nbsp%3Bto%20do%20the%20authentication%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FNOSCRIPT%3E%3C%2FDIV%3E%3C%2FDIV%3E%0A%3CH3%20id%3D%22toc-hId-1318125906%22%20id%3D%22toc-hId-1318125906%22%3ECreate%20website.%3C%2FH3%3E%0A%3CP%3EYou%20can%20create%20the%20static%20by%20following%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fblobs%2Fstorage-blob-static-website-how-to%3Ftabs%3Dazure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EHost%20a%20static%20website%20in%20Azure%20Storage%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Mobarqaw_2-1607955738597.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F240171i455AF7218A99FD46%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Mobarqaw_2-1607955738597.png%22%20alt%3D%22Mobarqaw_2-1607955738597.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--489328557%22%20id%3D%22toc-hId--489328557%22%3ECreate%20the%20Active%20Directory%20application%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20followed%20the%20article%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fdevelop%2Fquickstart-v2-javascript%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fdevelop%2Fquickstart-v2-javascript%3C%2FA%3E%3C%2FP%3E%0A%3CH5%20id%3D%22toc-hId--1595718442%22%20id%3D%22toc-hId--1595718442%22%3ERegister%20your%20application%3C%2FH5%3E%0A%3COL%3E%0A%3CLI%3ESign%20in%20to%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EAzure%20portal%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3EIf%20you%20have%20access%20to%20multiple%20tenants%2C%20use%20the%26nbsp%3B%3CSTRONG%3EDirectory%20%2B%20subscription%3C%2FSTRONG%3E%26nbsp%3Bfilter%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Mobarqaw_3-1607955738600.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F240169i045C969E6DEE7789%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Mobarqaw_3-1607955738600.png%22%20alt%3D%22Mobarqaw_3-1607955738600.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%26nbsp%3Bin%20the%20top%20menu%20to%20select%20the%20tenant%20in%20which%20you%20want%20to%20register%20an%20application.%3C%2FLI%3E%0A%3CLI%3ESearch%20for%20and%20select%26nbsp%3B%3CSTRONG%3EAzure%20Active%20Directory%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3EUnder%26nbsp%3B%3CSTRONG%3EManage%3C%2FSTRONG%3E%2C%20select%26nbsp%3B%3CSTRONG%3EApp%20registrations%3C%2FSTRONG%3E%26nbsp%3B%26gt%3B%26nbsp%3B%3CSTRONG%3ENew%20registration%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3EEnter%20a%26nbsp%3B%3CSTRONG%3EName%3C%2FSTRONG%3E%26nbsp%3Bfor%20your%20application.%20Users%20of%20your%20app%20might%20see%20this%20name%2C%20and%20you%20can%20change%20it%20later.%3C%2FLI%3E%0A%3CLI%3EUnder%26nbsp%3B%3CSTRONG%3ESupported%20account%20types%3C%2FSTRONG%3E%2C%20select%26nbsp%3B%3CSTRONG%3EAccounts%20in%20any%20organizational%20directory%20and%20personal%20Microsoft%20accounts%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3ESelect%26nbsp%3B%3CSTRONG%3ERegister%3C%2FSTRONG%3E.%20On%20the%20app%26nbsp%3B%3CSTRONG%3EOverview%3C%2FSTRONG%3E%26nbsp%3Bpage%2C%20note%20the%26nbsp%3B%3CSTRONG%3EApplication%20(client)%20ID%3C%2FSTRONG%3E%26nbsp%3Bvalue%20for%20later%20use.%3C%2FLI%3E%0A%3CLI%3EUnder%26nbsp%3B%3CSTRONG%3EPlatform%20Configurations%3C%2FSTRONG%3E%2C%20select%26nbsp%3B%3CSTRONG%3EAdd%20a%20platform%3C%2FSTRONG%3E.%20A%20panel%20opens%20on%20the%20left.%20There%2C%20select%20the%26nbsp%3B%3CSTRONG%3EWeb%20Applications%3C%2FSTRONG%3E%26nbsp%3Bregion.%3C%2FLI%3E%0A%3CLI%3EStill%20on%20the%20left%2C%20set%20the%26nbsp%3B%3CSTRONG%3ERedirect%20URI%3C%2FSTRONG%3E%26nbsp%3Bvalue%20to%26nbsp%3B%5Bthe%20static%20website%20URL%5D%20Then%2C%20select%26nbsp%3B%3CSTRONG%3EAccess%20Token%3C%2FSTRONG%3E%26nbsp%3Band%26nbsp%3B%3CSTRONG%3EID%20Token%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3ESelect%26nbsp%3B%3CSTRONG%3EConfigure%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--1606221546%22%20id%3D%22toc-hId--1606221546%22%3E1.2.2%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Build%20the%20HTML%20page%20with%20msal.js%3C%2FH4%3E%0A%3CP%3ECreate%20HTML%20with%20the%20below%20content%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E!DOCTYPE%20html%26gt%3B%0A%0A%0A%0A%20%20%26lt%3Bmeta%20charset%3D%22UTF-8%22%20%2F%26gt%3B%0A%20%20%26lt%3Bmeta%20name%3D%22viewport%22%20content%3D%22width%3Ddevice-width%2C%20initial-scale%3D1.0%2C%20shrink-to-fit%3Dno%22%20%2F%26gt%3B%0A%20%20%3CTITLE%3EDemo%20for%20using%20Logic%20app%20using%20Azure%20Active%20Directory%20Authorization%20Policies%20%3C%2FTITLE%3E%0A%20%20%3CLINK%20rel%3D%22SHORTCUT%20ICON%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ffavicon.svg%22%20type%3D%22image%2Fx-icon%22%20%2F%3E%0A%0A%20%20%3C!--%20msal.min.js%20can%20be%20used%20in%20the%20place%20of%20msal.js%3B%20included%20msal.js%20to%20make%20debug%20easy%20--%3E%0A%20%20%3CSCRIPT%20type%3D%22text%2Fjavascript%22%20src%3D%22https%3A%2F%2Falcdn.msauth.net%2Flib%2F1.4.4%2Fjs%2Fmsal.js%22%20integrity%3D%22sha384-fTmwCjhRA6zShZq8Ow5ZkbWwmgp8En46qW6yWpNEkp37MkV50I%2FV2wjzlEkQ8eWD%22%20crossorigin%3D%22anonymous%22%3E%3C%2FSCRIPT%3E%0A%0A%20%20%3C!--%20msal.js%20with%20a%20fallback%20to%20backup%20CDN%20--%3E%0A%20%20%3CSCRIPT%20type%3D%22text%2Fjavascript%22%3E%0A%20%20%20%20if%20(typeof%20Msal%20%3D%3D%3D%20'undefined')%20document.write(unescape(%22%253Cscript%20src%3D'https%3A%2F%2Falcdn.msftauth.net%2Flib%2F1.4.4%2Fjs%2Fmsal.js'%20type%3D'text%2Fjavascript'%20%253E%253C%2Fscript%253E%22))%3B%0A%20%20%3C%2FSCRIPT%3E%0A%0A%20%20%3C!--%20adding%20Bootstrap%204%20for%20UI%20components%20%20--%3E%0A%20%20%3CLINK%20rel%3D%22stylesheet%22%20href%3D%22https%3A%2F%2Fstackpath.bootstrapcdn.com%2Fbootstrap%2F4.4.1%2Fcss%2Fbootstrap.min.css%22%20integrity%3D%22sha384-Vkoo8x4CGsO3%2BHhxv8T%2FQ5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh%22%20crossorigin%3D%22anonymous%22%20%2F%3E%0A%0A%0A%0A%20%20%3CNAV%20class%3D%22navbar%20navbar-expand-lg%20navbar-dark%20bg-primary%22%3E%0A%20%20%20%20%3CA%20class%3D%22navbar-brand%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%3EStorage%20account%20Gate%20keeper%20using%20logic%20app%20%3C%2FA%3E%0A%20%20%20%20%3CDIV%20class%3D%22btn-group%20ml-auto%20dropleft%22%3E%0A%20%20%20%20%20%20%3CBUTTON%20type%3D%22button%22%20id%3D%22signIn%22%20class%3D%22btn%20btn-secondary%22%20onclick%3D%22signIn()%22%3ESign%20In%3C%2FBUTTON%3E%0A%20%20%20%20%20%20%3CBUTTON%20type%3D%22button%22%20id%3D%22signOut%22%20class%3D%22btn%20btn-success%20d-none%22%20onclick%3D%22signOut()%22%3ESign%20Out%3C%2FBUTTON%3E%0A%20%20%20%20%3C%2FDIV%3E%0A%20%20%3C%2FNAV%3E%0A%20%20%3CBR%20%2F%3E%0A%20%20%3CH5%20class%3D%22card-header%20text-center%22%20id%3D%22toc-hId--915660072%22%3Ethis%20is%20a%20demo%20only%20site%20%3C%2FH5%3E%0A%20%20%3CBR%20%2F%3E%0A%20%20%3CDIV%20class%3D%22row%22%20style%3D%22margin%3Aauto%22%3E%0A%20%20%20%20%3CDIV%20id%3D%22card-div%22%20class%3D%22col-md-3%20d-none%22%3E%0A%20%20%20%20%20%20%3CDIV%20class%3D%22card%20text-center%22%3E%0A%20%20%20%20%20%20%20%20%3CDIV%20class%3D%22card-body%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3CH5%20class%3D%22card-title%22%20id%3D%22welcomeMessage%22%20id%3D%22toc-hId-1571852761%22%3EPlease%20sign-in%20to%20see%20your%20profile%20and%20read%20your%20mails%3C%2FH5%3E%0A%20%20%20%20%20%20%20%20%20%20%3CDIV%20id%3D%22profile-div%22%3E%3C%2FDIV%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBR%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBR%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBUTTON%20class%3D%22btn%20btn-primary%22%20id%3D%22seeProfile%22%20onclick%3D%22downloadFile()%22%3EDownload%20File%3C%2FBUTTON%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBR%20%2F%3E%0A%20%20%20%20%20%20%20%20%3C%2FDIV%3E%0A%20%20%20%20%20%20%3C%2FDIV%3E%0A%20%20%20%20%3C%2FDIV%3E%0A%20%20%20%20%3CBR%20%2F%3E%0A%20%20%20%20%3CBR%20%2F%3E%0A%20%20%20%20%3CDIV%20class%3D%22col-md-4%22%3E%0A%20%20%20%20%20%20%3CDIV%20class%3D%22list-group%22%20id%3D%22list-tab%22%20role%3D%22tablist%22%3E%0A%20%20%20%20%20%20%3C%2FDIV%3E%0A%20%20%20%20%3C%2FDIV%3E%0A%20%20%20%20%3CDIV%20class%3D%22col-md-5%22%3E%0A%20%20%20%20%20%20%3CDIV%20class%3D%22tab-content%22%20id%3D%22nav-tabContent%22%3E%0A%20%20%20%20%20%20%3C%2FDIV%3E%0A%20%20%20%20%3C%2FDIV%3E%0A%20%20%3C%2FDIV%3E%0A%20%20%3CBR%20%2F%3E%0A%20%20%3CBR%20%2F%3E%0A%20%20%3C!--%20importing%20bootstrap.js%20and%20supporting%20js%20libraries%20--%3E%0A%20%20%3CSCRIPT%20src%3D%22https%3A%2F%2Fcode.jquery.com%2Fjquery-3.4.1.slim.min.js%22%20integrity%3D%22sha384-J6qa4849blE2%2BpoT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ%2Bn%22%20crossorigin%3D%22anonymous%22%3E%3C%2FSCRIPT%3E%0A%20%20%3CSCRIPT%20src%3D%22https%3A%2F%2Fstackpath.bootstrapcdn.com%2Fbootstrap%2F4.4.1%2Fjs%2Fbootstrap.min.js%22%20integrity%3D%22sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6%22%20crossorigin%3D%22anonymous%22%3E%3C%2FSCRIPT%3E%0A%20%20%3C!--%20importing%20app%20scripts%20(load%20order%20is%20important)%20--%3E%0A%20%20%3CSCRIPT%20type%3D%22text%2Fjavascript%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2FauthConfig.js%22%3E%3C%2FSCRIPT%3E%0A%20%20%3CSCRIPT%20type%3D%22text%2Fjavascript%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fui.js%22%3E%3C%2FSCRIPT%3E%0A%20%20%3CSCRIPT%20type%3D%22text%2Fjavascript%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2FauthPopup.js%22%3E%3C%2FSCRIPT%3E%0A%0A%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECreate%20file%20authPopup.js%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%2F%2F%20Create%20the%20main%20myMSALObj%20instance%0A%2F%2F%20configuration%20parameters%20are%20located%20at%20authConfig.js%0Aconst%20myMSALObj%20%3D%20new%20Msal.UserAgentApplication(msalConfig)%3B%0Avar%20Bearer%20%3D%20''%0Alet%20searchParams%20%3D%20new%20URLSearchParams(window.location.search)%0Alet%20fileParam%20%3D%20searchParams.get('file')%0Afunction%20signIn()%20%7B%0A%20%20myMSALObj.loginPopup(loginRequest)%0A%20%20%20%20.then(loginResponse%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20console.log(%22id_token%20acquired%20at%3A%20%22%20%2B%20new%20Date().toString())%3B%0A%20%20%20%20%20%20console.log(loginResponse)%3B%0A%0A%20%20%20%20%20%20if%20(myMSALObj.getAccount())%20%7B%0A%20%20%20%20%20%20%20%20Bearer%20%3D%20loginResponse.idToken.rawIdToken%3B%0A%20%20%20%20%20%20%20%20showWelcomeMessage(myMSALObj.getAccount())%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D).catch(error%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20console.log(error)%3B%0A%20%20%20%20%7D)%3B%0A%7D%0A%0Afunction%20signOut()%20%7B%0A%20%20myMSALObj.logout()%3B%0A%7D%0A%0A%2F%2Fendpoint%2C%20token%2C%20callback%0Afunction%20downloadFile()%20%7B%0A%0A%20%20const%20headers%20%3D%20new%20Headers()%3B%0A%20%20const%20bearer%20%3D%20%60Bearer%20%24%7BBearer%7D%60%3B%0A%0A%20%20headers.append(%22Authorization%22%2C%20bearer)%3B%0A%20%20headers.append(%22FileName%22%2C%20fileParam)%3B%0A%0A%20%20const%20options%20%3D%20%7B%0A%20%20%20%20method%3A%20%22post%22%2C%0A%20%20%20%20headers%3A%20headers%0A%20%20%7D%3B%0A%20%20fetch(logicAppUrl%2C%20options)%0A%20%20%20%20.then(resp%20%3D%26gt%3B%20resp.blob())%0A%20%20%20%20.then(blob%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20const%20url%20%3D%20window.URL.createObjectURL(blob)%3B%0A%20%20%20%20%20%20const%20a%20%3D%20document.createElement('a')%3B%0A%20%20%20%20%20%20a.style.display%20%3D%20'none'%3B%0A%20%20%20%20%20%20a.href%20%3D%20url%3B%0A%20%20%20%20%20%20%2F%2F%20the%20filename%20you%20want%0A%20%20%20%20%20%20a.download%20%3D%20fileParam%3B%0A%20%20%20%20%20%20document.body.appendChild(a)%3B%0A%20%20%20%20%20%20a.click()%3B%0A%20%20%20%20%20%20window.URL.revokeObjectURL(url)%3B%0A%20%20%20%20%20%20alert('your%20file%20has%20downloaded!')%3B%20%2F%2F%20or%20you%20know%2C%20something%20with%20better%20UX...%0A%20%20%20%20%7D)%0A%20%20%20%20.catch(error%20%3D%26gt%3B%20console.log(error))%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EauthConfig.js%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%20%0A%2F%2F%20Config%20object%20to%20be%20passed%20to%20Msal%20on%20creation.%0A%2F%2F%20For%20a%20full%20list%20of%20msal.js%20configuration%20parameters%2C%20%0A%2F%2F%20visit%20https%3A%2F%2Fazuread.github.io%2Fmicrosoft-authentication-library-for-js%2Fdocs%2Fmsal%2Fmodules%2F_authenticationparameters_.html%0Aconst%20msalConfig%20%3D%20%7B%0A%20%20auth%3A%20%7B%0A%20%20%20%20clientId%3A%20%227ebe8908-7acd-4e20-b1f4-24715b364cf0%22%2C%0A%20%20%20%20authority%3A%20%22https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%22%2C%0A%20%20%20%20redirectUri%3A%20%22https%3A%2F%2Flargfile.z6.web.core.windows.net%22%2C%0A%20%20%7D%2C%0A%20%20cache%3A%20%7B%0A%20%20%20%20cacheLocation%3A%20%22sessionStorage%22%2C%20%2F%2F%20This%20configures%20where%20your%20cache%20will%20be%20stored%0A%20%20%20%20storeAuthStateInCookie%3A%20false%2C%20%2F%2F%20Set%20this%20to%20%22true%22%20if%20you%20are%20having%20issues%20on%20IE11%20or%20Edge%0A%20%20%7D%0A%7D%3B%20%20%0A%20%20%0A%2F%2F%20Add%20here%20the%20scopes%20to%20request%20when%20obtaining%20an%20access%20token%20for%20MS%20Graph%20API%0A%2F%2F%20for%20more%2C%20visit%20https%3A%2F%2Fgithub.com%2FAzureAD%2Fmicrosoft-authentication-library-for-js%2Fblob%2Fdev%2Flib%2Fmsal-core%2Fdocs%2Fscopes.md%0Aconst%20loginRequest%20%3D%20%7B%0A%20%20scopes%3A%20%5B%22openid%22%2C%20%22profile%22%2C%20%22User.Read%22%5D%0A%7D%3B%0A%0Aconst%20logicAppUrl%3D'https%3A%2F%2Fprod-39.eastus.logic.azure.com%3A443%2Fworkflows%2F92083fac9d2c4805b153907db6976f86%2Ftriggers%2Fmanual%2Fpaths%2Finvoke%3Fapi-version%3D2016-10-01'%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH5%20id%3D%22toc-hId--915660072%22%20id%3D%22toc-hId--235601702%22%3ECreating%20the%20logic%20app%3C%2FH5%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20logic%20app%20will%20receive%20the%20request%20using%20HTTP%20and%20will%20pass%20the%20file%20name%20to%20the%20storage%20account%20action%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Mobarqaw_4-1607955738602.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F240172i7C59E4ABFB1EC2C5%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Mobarqaw_4-1607955738602.png%22%20alt%3D%22Mobarqaw_4-1607955738602.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--926163176%22%20id%3D%22toc-hId--246104806%22%3E1.3.1%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Enable%20logic%20app%20Azure%20Active%20Directory%20Authorization%20Policies%3C%2FH4%3E%0A%3CP%3EMake%20the%20issuer%20%3CA%20href%3D%22https%3A%2F%2Flogin.microsoftonline.com%2F9188040d-6c67-4c5b-b112-36a304b66dad%2Fv2.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Flogin.microsoftonline.com%2F9188040d-6c67-4c5b-b112-36a304b66dad%2Fv2.0%3C%2FA%3E%20%26nbsp%3BThe%20GUID%20that%20indicates%20that%20the%20user%20is%20a%20consumer%20user%20from%20a%20Microsoft%20account%20is%26nbsp%3B9188040d-6c67-4c5b-b112-36a304b66dad%20for%20information%20at%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fdevelop%2Faccess-tokens%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fdevelop%2Faccess-tokens%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Mobarqaw_5-1607955738604.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F240173i7E9F8A5B4E64CC2A%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Mobarqaw_5-1607955738604.png%22%20alt%3D%22Mobarqaw_5-1607955738604.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMore%20information%20on%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Flogic-apps%2Flogic-apps-securing-a-logic-app%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESecure%20access%20and%20data%20-%20Azure%20Logic%20Apps%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ethe%20HTML%20and%20JavaScript%20attached%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1985428%22%20slang%3D%22en-US%22%3E%3CP%3EUse%20the%20logic%20app%20with%26nbsp%3Boauth2%3C%2FP%3E%0A%3CDIV%20id%3D%22gtx-trans%22%20style%3D%22position%3A%20absolute%3B%20left%3A%208px%3B%20top%3A%2031px%3B%22%3E%0A%3CDIV%20class%3D%22gtx-trans-icon%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1985428%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELogic%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Dec 15 2020 01:42 AM
Updated by: