title: setting js azure app service custom login authentication
body: <p>I started implementing 2 years ago my custom authentication in azure mobile service with node.js to use it in my jquery/cordova appery.io app. I have a database with users, passwords, etc and a login api in node.js backend that generates a valid jwt like this:</p>
  
  <p><a href="http://www.thejoyofcode.com/Exploring_custom_identity_in_Mobile_Services_Day_12_.aspx" rel="nofollow noreferrer">http://www.thejoyofcode.com/Exploring_custom_identity_in_Mobile_Services_Day_12_.aspx</a></p>
  
  <p><a href="http://chrisrisner.com/Version-1-of-the-Mobile-Services-JWT-token-has-been-deprecated" rel="nofollow noreferrer">http://chrisrisner.com/Version-1-of-the-Mobile-Services-JWT-token-has-been-deprecated</a></p>
  
  <p>But now i have been migrated to azure app service and don´t know how to implement custom authetication with javascript.</p>
  
  <p>At the examples above:</p>
  
  <p><em>"iss":"urn:microsoft:windows-azure:zumo",
  "ver":2,
  "aud":aud,</em></p>
  
  <p>But i have read that "aud" and "iss" must be my azure website and "sub" my own userId, to generate a valid jwt in my custom auth to use it in azure. Is it right?</p>
  
  <p><a href="https://shellmonger.com/2016/04/08/30-days-of-zumo-v2-azure-mobile-apps-day-5-custom-authentication/" rel="nofollow noreferrer">https://shellmonger.com/2016/04/08/30-days-of-zumo-v2-azure-mobile-apps-day-5-custom-authentication/</a></p>
  
  <p><em>The important thing is the token. There are some requirements for using 3rd party tokens with an Azure Mobile App:
      It must follow the Json Web Token format
      The user Id must be in the subject (sub) field
      The audience (aud) and issuer (iss) must be known and configured</em></p>
  
  <p>I do a call to my login API with ajax post and obtain a valid JWT token (<a href="http://jwt.io" rel="nofollow noreferrer">http://jwt.io</a>), but i don´t know the correct process to login and use azure services because i don´t know the correct way to use it on my app. I have changed MobileServices.Web.min.js to azure-mobile-apps-client.js in the app.
  <a href="https://github.com/Azure/azure-mobile-apps-js-client" rel="nofollow noreferrer">https://github.com/Azure/azure-mobile-apps-js-client</a></p>
  
  <p>Can i use the jwt token created in azure node.js or exchange it for a session token and use client.login() method by JS SDK?</p>
  
  <p>EDIT:
  I see the light again adding to ajax POST
              <code>headers: {'X-ZUMO-AUTH': usuarioToken},</code></p>
  
  <p>So my "authenticated users only" api works again with the old MobileServices.Web.min.js! It also works perfect with invokeApi method:</p>
  
  <pre><code>var mobileClient = new WindowsAzure.MobileServiceClient(urlApp,keyApp);
  mobileClient.currentUser = {
      userId: myCustomUserId,
      mobileServiceAuthenticationToken: myCustomToken
  };
  mobileClient
      .invokeApi('data', {
              method: 'POST',
              headers: {'X-ZUMO-AUTH': myCustomToken},
              body: JSON.stringify(theData)
          }) //end invokeApi
      .done(
          function (response) {
              alert(response);
          },
          function (error) {
              alert("error"));
          }
      ); //end done
  </code></pre>
  
  <p>The mobileClient generated contains this data:</p>
  
  <pre><code>mobileClient= {"applicationUrl":"https://xxx.azure-mobile.net/","applicationKey":"hGhzxxx","version":"ZUMO/1.2 (lang=Web; os=--; os_version=--; arch=--; version=1.2.21003.0)","currentUser":{"userId":"Custom:25F600BB-xxxx-xxxx-xxxx-8329BCCF31D2","mobileServiceAuthenticationToken":"ey__rest of jwt token"},"_serviceFilter":null,"_login":{"_loginState":{"inProcess":false,"cancelCallback":null},"ignoreFilters":true},"push":{"_apns":null,"_gcm":null,"_registrationManager":null}}
  </code></pre>
  
  <p>I will try again wiht the new azure-mobile-apps-client.js
  Any comment will be welcome</p>