title: Implementing linkedin oauth2 with ionic/angularjs on frontend (hybrid mobile app) and expressjs+passportjs+mongodb on backend
body: <p>My backend is setup on AWS and is running an expess webserver. It is configured with passportjs.</p>
  
  <p>On the frontend I want all users to login through linkedin. When they press the button it issues a http GET command using angular's $http.get service. The basic workflow I am trying to achieve is the following:</p>
  
  <p>1) Client opens the app and hits sign in with linkedin and the get request is issued to the backend express server</p>
  
  <p>2) The express server uses passportjs for linkedin oauth2 authentication which subsequently forwards the request to the linkedin server</p>
  
  <p>3) Linkedin's server then responds to the client with a login page in response to the clients request </p>
  
  <p>4) Once the page in step 3 is successfully verified with the users login credentials, the access token is sent to the express server since I configured the linkedin redirect URL to it. </p>
  
  <p>5) The express server then receives the user profile details and then sends across some data to the client.</p>
  
  <p>Since I am using the ionic Framework I would like to receive the data and then load up a page defined in the ionic templates folder(local to the frontend) and populate it with data received from the server at step 5. </p>
  
  <p>In order to do this I am trying to issue an $http.get request which fails with the error:
  404 on <strong>Step 2</strong>. </p>
  
  <pre><code>$http.get('http://www.example.com:3000/auth/linkedin/').
  success(function(data, status, headers, config) {
      console.log('success');
  }).
  error(function(data, status, headers, config) {
      console.log('failure '+data+', ' +status +', '+headers+', '+config)
  });
  </code></pre>
  
  <p>This prints out:</p>
  
  <pre><code>"failure , 404, function (name) {
      "use strict";
  
      if (!headersObj) headersObj =  parseHeaders(headers);
  
      if (name) {
        return headersObj[lowercase(name)] || null;
      }
  
      return headersObj;
  }, [object Object]"
  </code></pre>
  
  <p>I am not sure if this is the way to go about it. 
  The other method that gave more success was using <code>window.location('http://www.example.com:3000/auth/linkedin/'</code>). This was able to follow up the redirect to the linkedin login page and upon successful login, the profile was returned to the express server. This method worked fine upto <strong>step 4</strong>. The problem was at <strong>step 5</strong>, I am not able redirect the user back to the other templates defined in the app.</p>