title: Custom authentication integration with parse-server and auth0
body: <p>I would like to use auth0.com in conjunction with the open source-parse server.</p>
  
  <p>My current approach is to obtain the token from auth0 by using their standard login through the Lock library for iOS. With that token I would like to call a custom authentication method on my parse-server, that checks whether the token is valid and if it is will log in the user.</p>
  
  <p>My problem is that there is almost no documentation on writing custom oauth for parse-server.</p>
  
  <p>So far, I have this code for my custom auth.</p>
  
  <pre><code>var Parse = require('parse/node').Parse;
  
  function validateAuthData(authData, options) {
    console.log('validateAuthData()');
    return new Promise((resolve, reject) =&gt; {
      try {
        var decoded = jwt.verify(authData.access_token, opions.sharedSecret);
        if (authData.id === decoded.sub) {
          resolve({});
        }
        throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Unauthorized');
      } catch(e) {
        throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, e.message);
      }
    });
  }
  
  function validateAppId(appIds, authData) {
    console.log('validateAppId()');
    return Promise.resolve();
  }
  
  module.exports = {
    validateAppId: validateAppId,
    validateAuthData: validateAuthData
  };
  </code></pre>
  
  <p>However, it doesn't work and also I don't understand how this code can be used to authenticate a specific user. Does the parse-server do database look-ups to match the specific auth data to a specific user? Also, how can I register a new user with custom auth. What happens when a user tries to log in but he doesn't exist yet in my parse database?</p>
  
  <p>An alternative seems to be <a href="https://stackoverflow.com/questions/34492697/parse-user-authenticated-using-auth0">this</a>, using a rule an auth0.com. What are the differences and how would the rule work? I have very little experience with authentication and oauth and jwt's.</p>
  
  <p>Lastly, I am using <a href="https://stackoverflow.com/questions/37255006/how-to-authenticate-a-user-in-parse-ios-sdk-using-oauth">this</a> to call my custom auth from my iOS client. However this doesn't work either, but I am not sure whether it is due to the iOS part or because my custom auth isn't working yet.</p>
  
  <p>In conclusion, I am having trouble with something that seems rather easy. I want to use auth0 as my authentication provider and I want to integrate it was the parse-server, since I really appreciate the convenience around parse and the client sdk's. I am fairly certain that more people have a similar problem, however I have not found any definitive resource on how to properly do this.</p>
  
  <p><em>Further Links</em></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/34492697/parse-user-authenticated-using-auth0">Parse user authenticated using Auth0</a></li>
  <li><a href="https://auth0.com/blog/2016/03/07/hapijs-authentication-secure-your-api-with-json-web-tokens/" rel="noreferrer">https://auth0.com/blog/2016/03/07/hapijs-authentication-secure-your-api-with-json-web-tokens/</a></li>
  <li><a href="https://github.com/ParsePlatform/parse-server/wiki/OAuth" rel="noreferrer">https://github.com/ParsePlatform/parse-server/wiki/OAuth</a></li>
  <li><a href="https://jwt.io/introduction/" rel="noreferrer">https://jwt.io/introduction/</a></li>
  </ul>