Bug 45516: Rewrite getToken function

It now returns a deferred object which is passed undefined, false or the token

Change-Id: Ib0fd3da664239bdb7866433acdbb452bfa28c89d