Calling Static Web Apps authenticated API endpoints

Published Jul 11 2021 10:04 PM 3,581 Views
Microsoft

Static Web Apps provides built in authentication and authorisation, as well as BYO options (like Auth0 or Okta) and this is all handled by the SWA platform.

For local development, we can use the cli tool that can simulate how an authenticated experience works for local dev, without the hassle of setting up custom OAuth endpoints or anything like that.

This all works together nicely to make it easy to build authenticated experiences, test them locally and then deploy to Azure.

The problem

While working on some content for an upcoming post, I hit a problem. I was building an authenticated experience and I wanted to test calling the API, but didn’t want to have to click through all the screens that would get me to that point. I just wanted to use something like REST Client for VS Code (or Postman, Insomniac, Fiddler, etc.) to call a specific API endpoint in an authenticated manner.

But since we go via the cli, or in production, the SWA proxy (I’m not sure it’s really a proxy server, but that’s what I call the thing that sits in front of your web and API endpoints to handle routing/auth/etc.), and not directly to the API, it poses a problem… how does auth happen?. It’s just taken care of by the platform, headers are injected, auth tokens are created, and as a user, you don’t need to think about it.

How SWA tracks auth

It’s time to get under the hood of Static Web Apps and try and work out how we can tell it that this inbound request from REST Client is authenticated and to pass the user information to the Functions backend.

Since we don’t have access to the Static Web Apps source code, we’ll have to dig around in the cli, although it’s not the same, it’s doing something to set the right headers.

The cli works by intercepting the requests that come in and sending them to either the web app, API or its built in mock auth server, and for the API, that happens here with the thing we’re specifically looking for that sets the headers happening in this callback. This calls the injectClientPrincipalCookies method and now we’re starting to get somewhere.

What it’s doing is looking for a specific cookie, named StaticWebAppsAuthCookie, which becomes the header that you unpack in the API to get the user info (or use my nifty JavaScript library).

Simulating auth from REST tools

We now know the value that is expected by the cli to pass to the API, and it’s something that we can get by opening the web app and going through an auth flow, then open up the browser dev tools and go to the Application tab -> Cookies:

 

01.png

Copy the cookie value, and it’s time to use your favourite REST tool, I’ll be using REST Client for VS Code and for the app I’m using my Auth0 SWA sample.

Let’s create an initial API call:

### Local
GET http://localhost:4280/api/get-message

Now, if you click the Send Request option above the request name it’ll give you back a response in a new tab:

HTTP/1.1 200 OK
connection: close
date: Fri, 02 Jul 2021 05:42:49 GMT
content-type: text/plain; charset=utf-8
server: Kestrel
transfer-encoding: chunked

This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response. There is no logged in user

Nice! Our API is working, next up is to add the cookie to the request. With REST Client, we do that by adding a Cookie header, and custom headers are added to a request as subsequent lines from the one containing the HTTP request:

## Local
GET http://localhost:4280/api/get-message
Cookie: StaticWebAppsAuthCookie=<your cookie value here>

I’m logged in with a mock user that has the userDetail value being test_user@auth0.com, so the response is:

HTTP/1.1 200 OK
connection: close
date: Fri, 02 Jul 2021 05:45:16 GMT
content-type: text/plain; charset=utf-8
server: Kestrel
transfer-encoding: chunked

This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response. The user is test_user@auth0.com

:party_popper: We are making an authenticated requests from an external tool to SWA.

It you want to do this against a deployed SWA app, it’s the same process, although the cookie is a lot bigger (I assume it’s doing some better security than the cli :rolling_on_the_floor_laughing:) and I take no responsibility for it breaking down the track, as I don’t know how the cookie is really used!

Conclusion

Static Web Apps authentication is great for adding security to an API, but it does become a little more challenging when we want to call that API from tools that we’re commonly using for API testing.

Thankfully, we’re able to simulate this by injecting a cookie to our requests that will “trick” the cli (and Azure) into thinking it was an authenticated request, passing the right user information down to the API.

Just be aware - trying to poke too much at security against the Azure resource is probably not the best idea, but then again, we don’t to dev against production do we… ;)

%3CLINGO-SUB%20id%3D%22lingo-sub-2536870%22%20slang%3D%22en-US%22%3ECalling%20Static%20Web%20Apps%20authenticated%20API%20endpoints%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2536870%22%20slang%3D%22en-US%22%3E%3CP%3EStatic%20Web%20Apps%20provides%20built%20in%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fauthentication-authorization%3FWT.mc_id%3Djavascript-34097-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eauthentication%20and%20authorisation%3C%2FA%3E%2C%20as%20well%20as%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fauthentication-custom%3Ftabs%3Daad%26amp%3BWT.mc_id%3Djavascript-34097-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EBYO%20options%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E(like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fapps-on-azure%2Fusing-auth0-with-static-web-apps%2Fba-p%2F2353653%22%20target%3D%22_self%22%3EAuth0%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eor%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fapps-on-azure%2Fusing-okta-with-static-web-apps%2Fba-p%2F2353700%22%20target%3D%22_self%22%3EOkta%3C%2FA%3E)%20and%20this%20is%20all%20handled%20by%20the%20SWA%20platform.%3C%2FP%3E%0A%3CP%3EFor%20local%20development%2C%20we%20can%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fapps-on-azure%2Fleveling-up-static-web-apps-with-the-cli%2Fba-p%2F2406567%22%20target%3D%22_self%22%3Ecli%20tool%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ethat%20can%20simulate%20how%20an%20authenticated%20experience%20works%20for%20local%20dev%2C%20without%20the%20hassle%20of%20setting%20up%20custom%20OAuth%20endpoints%20or%20anything%20like%20that.%3C%2FP%3E%0A%3CP%3EThis%20all%20works%20together%20nicely%20to%20make%20it%20easy%20to%20build%20authenticated%20experiences%2C%20test%20them%20locally%20and%20then%20deploy%20to%20Azure.%3C%2FP%3E%0A%3CH2%20id%3D%22the-problem%22%20id%3D%22toc-hId--411488880%22%20id%3D%22toc-hId--411488880%22%3EThe%20problem%3C%2FH2%3E%0A%3CP%3EWhile%20working%20on%20some%20content%20for%20an%20upcoming%20post%2C%20I%20hit%20a%20problem.%20I%20was%20building%20an%20authenticated%20experience%20and%20I%20wanted%20to%20test%20calling%20the%20API%2C%20but%20didn%E2%80%99t%20want%20to%20have%20to%20click%20through%20all%20the%20screens%20that%20would%20get%20me%20to%20that%20point.%20I%20just%20wanted%20to%20use%20something%20like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dhumao.rest-client%26amp%3BWT.mc_id%3Djavascript-34097-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EREST%20Client%20for%20VS%20Code%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E(or%20Postman%2C%20Insomniac%2C%20Fiddler%2C%20etc.)%20to%20call%20a%20specific%20API%20endpoint%20in%20an%20authenticated%20manner.%3C%2FP%3E%0A%3CP%3EBut%20since%20we%20go%20via%20the%20cli%2C%20or%20in%20production%2C%20the%20SWA%20proxy%20(I%E2%80%99m%20not%20sure%20it%E2%80%99s%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3Ereally%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ea%20proxy%20server%2C%20but%20that%E2%80%99s%20what%20I%20call%20the%20thing%20that%20sits%20in%20front%20of%20your%20web%20and%20API%20endpoints%20to%20handle%20routing%2Fauth%2Fetc.)%2C%20and%20not%20directly%20to%20the%20API%2C%20it%20poses%20a%20problem%E2%80%A6%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ehow%20does%20auth%20happen%3F%3C%2FSTRONG%3E.%20It%E2%80%99s%20just%20taken%20care%20of%20by%20the%20platform%2C%20headers%20are%20injected%2C%20auth%20tokens%20are%20created%2C%20and%20as%20a%20user%2C%20you%20don%E2%80%99t%20need%20to%20think%20about%20it.%3C%2FP%3E%0A%3CH2%20id%3D%22how-swa-tracks-auth%22%20id%3D%22toc-hId-2076023953%22%20id%3D%22toc-hId-2076023953%22%3EHow%20SWA%20tracks%20auth%3C%2FH2%3E%0A%3CP%3EIt%E2%80%99s%20time%20to%20get%20under%20the%20hood%20of%20Static%20Web%20Apps%20and%20try%20and%20work%20out%20how%20we%20can%20tell%20it%20that%20this%20inbound%20request%20from%20REST%20Client%20is%20authenticated%20and%20to%20pass%20the%20user%20information%20to%20the%20Functions%20backend.%3C%2FP%3E%0A%3CP%3ESince%20we%20don%E2%80%99t%20have%20access%20to%20the%20Static%20Web%20Apps%20source%20code%2C%20we%E2%80%99ll%20have%20to%20dig%20around%20in%20the%20cli%2C%20although%20it%E2%80%99s%20not%20the%20same%2C%20it%E2%80%99s%20doing%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3Esomething%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20set%20the%20right%20headers.%3C%2FP%3E%0A%3CP%3EThe%20cli%20works%20by%20intercepting%20the%20requests%20that%20come%20in%20and%20sending%20them%20to%20either%20the%20web%20app%2C%20API%20or%20its%20built%20in%20mock%20auth%20server%2C%20and%20for%20the%20API%2C%20that%20happens%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fstatic-web-apps-cli%2Fblob%2Fmain%2Fsrc%2Fmsha%2Fhandlers%2Ffunction.handler.ts%23L50%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewith%20the%20thing%20we%E2%80%99re%20specifically%20looking%20for%20that%20sets%20the%20headers%20happening%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fstatic-web-apps-cli%2Fblob%2Fmain%2Fsrc%2Fmsha%2Fhandlers%2Ffunction.handler.ts%23L71-L74%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ein%20this%20callback%3C%2FA%3E.%20This%20calls%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fstatic-web-apps-cli%2Fblob%2Fmain%2Fsrc%2Fmsha%2Fhandlers%2Ffunction.handler.ts%23L28-L48%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CCODE%3EinjectClientPrincipalCookies%3C%2FCODE%3E%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20and%20now%20we%E2%80%99re%20starting%20to%20get%20somewhere.%3C%2FP%3E%0A%3CP%3EWhat%20it%E2%80%99s%20doing%20is%20looking%20for%20a%20specific%20cookie%2C%20named%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EStaticWebAppsAuthCookie%3C%2FCODE%3E%2C%20which%20becomes%20the%20header%20that%20you%20unpack%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstatic-web-apps%2Fuser-information%3Ftabs%3Djavascript%26amp%3BWT.mc_id%3Djavascript-34097-aapowell%23api-functions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ein%20the%20API%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20get%20the%20user%20info%20(or%20use%20my%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Faaronpowell%2Fazure-static-web-apps-api-auth%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Enifty%20JavaScript%20library%3C%2FA%3E).%3C%2FP%3E%0A%3CH2%20id%3D%22simulating-auth-from-rest-tools%22%20id%3D%22toc-hId-268569490%22%20id%3D%22toc-hId-268569490%22%3ESimulating%20auth%20from%20REST%20tools%3C%2FH2%3E%0A%3CP%3EWe%20now%20know%20the%20value%20that%20is%20expected%20by%20the%20cli%20to%20pass%20to%20the%20API%2C%20and%20it%E2%80%99s%20something%20that%20we%20can%20get%20by%20opening%20the%20web%20app%20and%20going%20through%20an%20auth%20flow%2C%20then%20open%20up%20the%20browser%20dev%20tools%20and%20go%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApplication%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Etab%20-%26gt%3B%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ECookies%3C%2FSTRONG%3E%3A%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditoraaronpowell_0%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2201.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294929i567F924866D14396%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%2201.png%22%20alt%3D%2201.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ECopy%20the%20cookie%20value%2C%20and%20it%E2%80%99s%20time%20to%20use%20your%20favourite%20REST%20tool%2C%20I%E2%80%99ll%20be%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dhumao.rest-client%26amp%3BWT.mc_id%3Djavascript-34097-aapowell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EREST%20Client%20for%20VS%20Code%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20for%20the%20app%20I%E2%80%99m%20using%20my%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Faaronpowell%2Fswa-custom-auth-auth0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAuth0%20SWA%20sample%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20create%20an%20initial%20API%20call%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E%23%23%23%20Local%0AGET%20%3CA%20class%3D%22vglnk%22%20href%3D%22http%3A%2F%2Flocalhost%3A4280%2Fapi%2Fget-message%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CSPAN%3Ehttp%3C%2FSPAN%3E%3CSPAN%3E%3A%2F%2F%3C%2FSPAN%3E%3CSPAN%3Elocalhost%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3CSPAN%3E4280%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Eapi%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Eget%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3Emessage%3C%2FSPAN%3E%3C%2FA%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENow%2C%20if%20you%20click%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESend%20Request%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eoption%20above%20the%20request%20name%20it%E2%80%99ll%20give%20you%20back%20a%20response%20in%20a%20new%20tab%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3EHTTP%2F1.1%20200%20OK%0Aconnection%3A%20close%0Adate%3A%20Fri%2C%2002%20Jul%202021%2005%3A42%3A49%20GMT%0Acontent-type%3A%20text%2Fplain%3B%20charset%3Dutf-8%0Aserver%3A%20Kestrel%0Atransfer-encoding%3A%20chunked%0A%0AThis%20HTTP%20triggered%20function%20executed%20successfully.%20Pass%20a%20name%20in%20the%20query%20string%20or%20in%20the%20request%20body%20for%20a%20personalized%20response.%20There%20is%20no%20logged%20in%20user%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENice!%20Our%20API%20is%20working%2C%20next%20up%20is%20to%20add%20the%20cookie%20to%20the%20request.%20With%20REST%20Client%2C%20we%20do%20that%20by%20adding%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ECookie%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eheader%2C%20and%20custom%20headers%20are%20added%20to%20a%20request%20as%20subsequent%20lines%20from%20the%20one%20containing%20the%20HTTP%20request%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E%23%23%20Local%0AGET%20%3CA%20class%3D%22vglnk%22%20href%3D%22http%3A%2F%2Flocalhost%3A4280%2Fapi%2Fget-message%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CSPAN%3Ehttp%3C%2FSPAN%3E%3CSPAN%3E%3A%2F%2F%3C%2FSPAN%3E%3CSPAN%3Elocalhost%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3CSPAN%3E4280%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Eapi%3C%2FSPAN%3E%3CSPAN%3E%2F%3C%2FSPAN%3E%3CSPAN%3Eget%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3Emessage%3C%2FSPAN%3E%3C%2FA%3E%0ACookie%3A%20StaticWebAppsAuthCookie%3D%3CYOUR%20cookie%3D%22%22%20value%3D%22%22%20here%3D%22%22%3E%0A%3C%2FYOUR%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EI%E2%80%99m%20logged%20in%20with%20a%20mock%20user%20that%20has%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EuserDetail%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20being%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Etest_user%40auth0.com%3C%2FCODE%3E%2C%20so%20the%20response%20is%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3EHTTP%2F1.1%20200%20OK%0Aconnection%3A%20close%0Adate%3A%20Fri%2C%2002%20Jul%202021%2005%3A45%3A16%20GMT%0Acontent-type%3A%20text%2Fplain%3B%20charset%3Dutf-8%0Aserver%3A%20Kestrel%0Atransfer-encoding%3A%20chunked%0A%0AThis%20HTTP%20triggered%20function%20executed%20successfully.%20Pass%20a%20name%20in%20the%20query%20string%20or%20in%20the%20request%20body%20for%20a%20personalized%20response.%20The%20user%20is%20test_user%40auth0.com%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3Aparty_popper%3A%20We%20are%20making%20an%20authenticated%20requests%20from%20an%20external%20tool%20to%20SWA.%3C%2FP%3E%0A%3CP%3EIt%20you%20want%20to%20do%20this%20against%20a%20deployed%20SWA%20app%2C%20it%E2%80%99s%20the%20same%20process%2C%20although%20the%20cookie%20is%20a%20lot%20bigger%20(I%20assume%20it%E2%80%99s%20doing%20some%20better%20security%20than%20the%20cli%20%3Arolling_on_the_floor_laughing%3A)%20and%20I%20take%20no%20responsibility%20for%20it%20breaking%20down%20the%20track%2C%20as%20I%20don%E2%80%99t%20know%20how%20the%20cookie%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3Ereally%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eused!%3C%2FP%3E%0A%3CH2%20id%3D%22conclusion%22%20id%3D%22toc-hId--1538884973%22%20id%3D%22toc-hId--1538884973%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EStatic%20Web%20Apps%20authentication%20is%20great%20for%20adding%20security%20to%20an%20API%2C%20but%20it%20does%20become%20a%20little%20more%20challenging%20when%20we%20want%20to%20call%20that%20API%20from%20tools%20that%20we%E2%80%99re%20commonly%20using%20for%20API%20testing.%3C%2FP%3E%0A%3CP%3EThankfully%2C%20we%E2%80%99re%20able%20to%20simulate%20this%20by%20injecting%20a%20cookie%20to%20our%20requests%20that%20will%20%E2%80%9Ctrick%E2%80%9D%20the%20cli%20(and%20Azure)%20into%20thinking%20it%20was%20an%20authenticated%20request%2C%20passing%20the%20right%20user%20information%20down%20to%20the%20API.%3C%2FP%3E%0A%3CP%3EJust%20be%20aware%20-%20trying%20to%20poke%20too%20much%20at%20security%20against%20the%20Azure%20resource%20is%20probably%20not%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3Ebest%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eidea%2C%20but%20then%20again%2C%20we%20don%E2%80%99t%20to%20dev%20against%20production%20do%20we%E2%80%A6%20%3B)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2536870%22%20slang%3D%22en-US%22%3E%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EAuthenticated%26nbsp%3BSWA%26nbsp%3Bendpoints%26nbsp%3Bcan%26nbsp%3Bbe%26nbsp%3Btricky%26nbsp%3Bto%26nbsp%3Btest%2C%26nbsp%3Bas%26nbsp%3Byou%26nbsp%3Bdon't%26nbsp%3Bcontrol%26nbsp%3Bthe%26nbsp%3Bheaders...%26nbsp%3Buntil%26nbsp%3Bnow!%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2536870%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWeb%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Jul 11 2021 10:04 PM
Updated by: