After creating a webapp, I decided to venture into developing a mobile app using Ionic. The idea of making a progressive web app crossed my mind, but unfortunately Apple doesn't support it yet.
(By the way, I'm still quite new to all of this)
For military service verification, I am utilizing the id.me api which returns an access token in the redirect uri for making api requests.
I have two options in terms of implementation, either through my server or directly on the client side.
You can check out their process flow here
This is where things get a bit confusing with Ionic....
To initiate the process, I need to direct the user to id.me's authorization endpoint, typically done via the inappbrowser
https://api.id.me/oauth/authorize?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token&scope=SCOPE
The redirect from id.me will contain the access token...
Next step involves extracting and storing the token locally before closing out the InAppBrowser. However, I'm unsure about setting the uri. Should it be localhost? Does Ionic run on a local server when deployed on a platform?
Would something like this work?
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&redirect_uri=callback&response_type=token&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]*?)\&/)[1];
$window.localStorage.setItem('token', token);
$cordovaInAppBrowser.close();
}
});
If the callback uri is triggered, will that function execute?
My confusion deepens at this stage. While I understand how this would function in a local environment, does the callback uri persist once the app is built and deployed on a device? Does Ionic operate on a local server within the device itself?