Does the Azure Function coding language matter for B2C Tutorial

hampton123 1,175 Reputation points
2023-07-31T13:56:59.99+00:00

I have been following a tutorial on B2C, APIM, and a SPA linked here. I tried to follow the tutorial precisely, with the exception of some name changes. However, I made an adjustment to the Azure Function specified in the tutorial. Instead of using C# - which is provided in the tutorial - I used the Azure Function's default code in JavaScript/NodeJs because I one of my requirements is to use JS/NodeJS. When calling the API (after I log in via B2C), I encountered an error message indicating "SyntaxError: Unexpected end of JSON input". Could the issue be because I used NodeJS in place of C# for my Azure Function?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,447 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Microsoft Security Microsoft Entra Microsoft Entra External ID
Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. MikeUrnun 9,777 Reputation points Moderator
    2023-07-31T18:36:28.7733333+00:00

    Hello @hampton123 - Thanks for reaching out!

    I've just gone over the tutorial that you have referenced. It shouldn't matter whether you use the .NET or NodeJS runtime as long as the response types and content are the same which in this case is a plain text payload, and the default/boilerplate JS code should have worked as-is.

    The Javascript equivalent of the C# code is as follows:

    module.exports = async function (context, req) {     
    	context.log('JavaScript HTTP trigger function processed a request.');      
    	context.res = {         
    		body: `Hello World, time and date are ${new Date().toString()}`
    	}; 
    }
    

    Could you try this out and let me know if the same issue persists?

    The error message suggests that a JSON input was invalid so it's possible the issue could be elsewhere, i.e. with the SPA code or MSAL flow.


1 additional answer

Sort by: Most helpful
  1. hampton123 1,175 Reputation points
    2023-08-05T17:47:31.86+00:00

    Thanks to MikeUrnun I figured out that my configuration issue was the naming of my Azure Function. The request was being sent to an Azure Function that didn't exist - it was trying to call a function called "hello", when my actual function was left as the default name, so "HttpTrigger1". After I created another function named "hello", the system worked as planned.

    Just as MikeUrnun also mentioned, each step on the tutorial needs to be followed extremely closely! Any naming conventions need to be followed extremely closely.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.