Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Flash of inAppBrowser when already authentiated #8

Open
SunburnedGoose opened this issue May 24, 2016 · 5 comments
Open

Flash of inAppBrowser when already authentiated #8

SunburnedGoose opened this issue May 24, 2016 · 5 comments

Comments

@SunburnedGoose
Copy link
Member

The app starts and it doesn't know if it is authenticated. It opens the inAppBrowser to Bungie.net to get the token, and it will flash the inAppBrowser briefly. Need to add a timeout to the ref.show() method to give it a moment to grab the token and close quickly. If it isn't closing quickly, then there is something that should be shown.

@kyleshay
Copy link
Member

can we always hide it by default... and then if we need the login screen, toggle it to the front?

@kyleshay
Copy link
Member

kyleshay commented May 24, 2016

ripped out code/logic from old version

  function viaPhonegap(callback) {
    document.addEventListener('deviceready', function() {

        type = 'Wlid';
        var visible = false;
        var ref = window.open('https://www.bungie.net/en/User/SignIn/' + type, '_blank', 'location=no,hidden=yes');

        var tries = 0;
        var refStart = function(event) {
          if(event.url.indexOf('bungie.net/en/User/SignIn/') !== -1) {
            return;
          }
          if(event.url === 'https://www.bungie.net/') {
            (function query() {
              ref.executeScript({code: 'document.cookie'}, function(result) {
                ref.removeEventListener('loadstart', refStart);
                ref.close();
                _cookie = /bungled=(\d*);/.exec(result)[1];
                callback(_cookie);
              });
            })();
          } else {
            ref.show();
            visible = true;
          }
        }
        ref.addEventListener('loadstart', refStart);

      }, false);
  }

@SunburnedGoose
Copy link
Member Author

It is hidden by default but I show it if the first page that loads doesn't have the token.

Usually that first page is just the redirect back to Bungie.net if you're already logged into Microsoft or Sony. So that 'tricks' the logic into showing the inAppBrowser briefly and Bungie.net loads, and DIM grabs the token.

What I'm suggesting is wrapping the show() function in a timeout that I can cancel if I'm able to get the token within 1s or so. Should fix the issue. I'm just making this ticket so I don't forget when I'm out this week.

@kyleshay
Copy link
Member

ahhh, gotcha! yeah that would do it. nice!

@SunburnedGoose
Copy link
Member Author

I could sniff the event for the endpoint that is loaded but it's a timing issue really since the url signature of the redirect from the pre-authenticated page is not something I can anticipate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants