title: Handling Redirect Uri in Ionic for external API
body: <p>So I've built a webapp and am making a corresponding mobile app in Ionic. I'd like to make a progressive web app as it'd make my life easier, but I guess Apple doesn't support this yet. </p>
  
  <p>(p.s.  I am pretty new at this stuff)</p>
  
  <p>So I'm using the id.me api to verify military service, which sends back an access token in the redirect uri in order to make api requests. </p>
  
  <p>There are two ways I can do this, through my server, or through the client.</p>
  
  <p>Here is their webflow 
  <a href="https://developer.id.me/documentation#oauth-overview" rel="nofollow">https://developer.id.me/documentation#oauth-overview</a></p>
  
  <p>This is where I kind of get lost Ionic....</p>
  
  <p>So to kick off the webflow, I have to send the user to id.me's authorization endpoint, which I would do in the inappbrowser</p>
  
  <pre><code>https://api.id.me/oauth/authorize?client_id=CLIENT-ID&amp;redirect_uri=REDIRECT-URI&amp;response_type=token&amp;scope=SCOPE
  </code></pre>
  
  <p>to which id.me sends back an access token on the redirect... </p>
  
  <p>From there, I can snatch the token, save it to local storage and close out the inAppBrowser. What I don't know is where to set the uri? Is it localhost? When you build Ionic on your platform, is running on a local server? </p>
  
  <p>Would I do something like this? </p>
  
  <pre><code>angular.module('myApp', ['ionic', 'ngCordova']).controller('AppCtrl', 
  
  function($rootScope, $ionicPlatform, $cordovaInAppBrowser) {
      var callback = 'http://localhost:8100/callback';
      $scope.idAuth = function() {
        $ionicPlatform.ready(function() {
          var options = {
            location: 'yes',
            clearcache: 'no',
            toolbar: 'yes'
          };
          $cordovaInAppBrowser.open('https://api.id.me/oauth/authorize?client_id=CLIENT-ID&amp;redirect_uri=callback&amp;response_type=token&amp;scope=SCOPE', '_blank', options)
        });
      };
  
  
      $rootScope.$on('$cordovaInAppBrowser:loadstart', function(e, event) {
        //and this function is called, so you do something like
        if(event.url === callback){;
          let token = event.url.match(/\#(?:access_token)\=([\S\s]*?)\&amp;/)[1];
          $window.localStorage.setItem('token', token);
          $cordovaInAppBrowser.close();
        }
      });
  </code></pre>
  
  <p>Now, if that callback uri gets hit, it's going to run that function? </p>
  
  <p>Also, and this is where I'm lost. I get how this would work on a local development, but when you build and put this on a device, does that callback uri still exist? Is Ionic running on a local server on the device itself? </p>