# Azure Function Login Sample

This example shows a simple example of an authentication form that will gather respondent credentials, validate the credentials remotely using an Azure's function and return the full information of the user to the survey.

First start by setting up the user interface of your security function to ask the username and password from respondent.

![](/files/-MBG8FBaMaFXeShXhniR)

Then log into your Azure online portal to create a new Azure functions that will get the data posted by the user interface we have just created as a json object eg: {username:'value', password:'value'} and return a proper user object if the credential are valid.

ngSurvey expect to receive from the end point a simple json object eg: {name:'value', firstName:'value'}, all these properties of the object will be saved along respondent answers and can be used and piped anywhere in questions / answers using \_\_lowercasepropertyname\_\_ . In our example we can use \_\_name\_\_ to pipe the name returned by our azure function in any part of our survey.

Any kind of errors that must be returned from the http end point must be returned as an Http Bad Request with the message that will be shown to the respondent

Here our basic Azure function code that will check for the fake user credentials

```csharp
#r "Newtonsoft.Json"

  using System.Net;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Primitives;
  using Newtonsoft.Json;
  
  class User {
      public string Id; 
      public string Email;
      public string Name;
  }
  public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
  {
      string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
      dynamic data = JsonConvert.DeserializeObject(requestBody);
      // check user 
      if (data?.username == "JohnDoe" && data?.password =="MayTheForceBeWithYou") {
        // If user valid return an object  
        var user = new User();
          user.Id = "1234567";
          user.Email = "John@Doe.com";
          user.Name = "John doe";
          return (ActionResult)new OkObjectResult(user);
      } else {
          return new BadRequestObjectResult("Invalid user!");
      }
  }
```

That's it! You just extended ngSurvey with some new custom login business logic using a remote Azure function.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ngsurvey.com/form-management/security/security-items/http-security-function/azure-function-login-sample.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
