Authenticate to Azure Function from within App

1.3k Views Asked by At

I'm using Facebook Authentication for my Azure Function App, it works fine if I navigate to a function within the browser. I would like to invoke my functions from within an app but an unsure how to perform the authentication.

At current I am attempting to use the Facebook Client, this returns me an access_token that I am then forwarding to the ".auth/login/facebook/callback" function within my function app. Unfortunately that's as far as I can get, doing this via a GET returns HTML with JavaScript in, and doing it via a POST redirects back to Facebook.

What I really need is the cookie created by the azure function, AppServiceAuthSession, I believe I can then use this to call the functions.

Edit: I don't think i can just use the cookie, like I said above so I need to authenticate properly.

Nick.

1

There are 1 best solutions below

1
brettsam On BEST ANSWER

I was able to get the tokens passed along to the function app while using the Facebook Javascript SDK (I wasn't having any luck with the C# one) -- maybe this will get you moving in the right direction.

The client:

  1. Performs the login to Facebook, which returns an accessToken.
  2. Client needs to exchange this accessToken for an 'App Service Token'. It does this by making a POST to https://{app}.azurewebsites.net/.auth/login/facebook with the content { "access_token" : "{token from Facebook}" }. This will return back an authenticationToken.
  3. Use that authenticationToken in a header named x-zumo-auth. Make all requests to your function app using that header.

From within your function app, you should then have the current Principal set to that logged in user.

Related Questions in FACEBOOK-C#-SDK