title: Validating user in Azure Mobile App Against Exiting User Database
body: <p>I am writing my first Azure Mobile App and I want to implement "Custom Authentication" against an existing websites user database.</p>
  
  <p>In the existing ASP.Net website I have the usual dbo.AspNetUsers tables etc.</p>
  
  <p>I cannot work out how to call this existing website to authenticate a user.</p>
  
  <p>I have the following code but I am lost how to get the isValidAssertion function to talk to my existing user database from within the Axure Mobile App.</p>
  
  <p>It would be the equivalent of this line found in the website..</p>
  
  <pre><code>ApplicationSignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
  </code></pre>
  
  <p>So, I have the following code:</p>
  
  <pre><code>private static bool isValidAssertion(JObject assertion)
      {
          // this is where I want to call the existing user database
  
          // this is how it's done in the MVC website
          //ApplicationSignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
  
          return true;
      }
  
      public IHttpActionResult Post([FromBody] JObject assertion)
      {
          if (isValidAssertion(assertion)) // user-defined function, checks against a database
          {
              JwtSecurityToken token = AppServiceLoginHandler.CreateToken(new Claim[] { new Claim(JwtRegisteredClaimNames.Sub, (string)assertion["username"]) },
                  mySigningKey,
                  myAppURL,
                  myAppURL,
                  TimeSpan.FromHours(24));
              return Ok(new LoginResult()
              {
                  AuthenticationToken = token.RawData,
                  User = new LoginResultUser() { UserId = (string)assertion["username"] }
              });
          }
          else // user assertion was not valid
          {
              return ResponseMessage(Request.CreateUnauthorizedResponse());
          }
      }
  </code></pre>
  
  <p>Can anyone point me in the right direction please?</p>