From 6291241ffc364422b4148f543c61b212758e4cfb Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Tue, 30 Aug 2016 00:36:48 -0700 Subject: [PATCH] removed $timeout from oauth2, fixed cordova issue with oauth2 --- src/oauth2.ts | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/oauth2.ts b/src/oauth2.ts index 679fdcde..03b53b89 100644 --- a/src/oauth2.ts +++ b/src/oauth2.ts @@ -70,37 +70,32 @@ export default class OAuth2 { init(options: IOAuth2Options, userData: any): angular.IPromise { return this.$q((resolve, reject) => { angular.extend(this.defaults, options); - this.$timeout(() => { - const stateName = this.defaults.name + '_state'; - const { name, state, popupOptions, redirectUri, responseType } = this.defaults; - - if (typeof state === 'function') { - this.SatellizerStorage.set(stateName, state()); - } else if (typeof state === 'string') { - this.SatellizerStorage.set(stateName, state); - } - - const url = [this.defaults.authorizationEndpoint, this.buildQueryString()].join('?'); - this.SatellizerPopup.open(url, name, popupOptions); + const stateName = this.defaults.name + '_state'; + const { name, state, popupOptions, redirectUri, responseType } = this.defaults; - this.SatellizerPopup.polling(redirectUri).then((oauth: any): void|angular.IPromise|angular.IHttpPromise => { + if (typeof state === 'function') { + this.SatellizerStorage.set(stateName, state()); + } else if (typeof state === 'string') { + this.SatellizerStorage.set(stateName, state); + } - if (responseType === 'token' || !url) { - return resolve(oauth); - } + const url = [this.defaults.authorizationEndpoint, this.buildQueryString()].join('?'); - if (oauth.state && oauth.state !== this.SatellizerStorage.get(stateName)) { - return reject(new Error( - 'The value returned in the state parameter does not match the state value from your original ' + - 'authorization code request.' - )); - } + this.SatellizerPopup.open(url, name, popupOptions, redirectUri).then((oauth: any): void|angular.IPromise|angular.IHttpPromise => { + if (responseType === 'token' || !url) { + return resolve(oauth); + } - resolve(this.exchangeForToken(oauth, userData)); - }) - .catch(error => reject(error)); - }); + if (oauth.state && oauth.state !== this.SatellizerStorage.get(stateName)) { + return reject(new Error( + 'The value returned in the state parameter does not match the state value from your original ' + + 'authorization code request.' + )); + } + + resolve(this.exchangeForToken(oauth, userData)); + }).catch(error => reject(error)); }); }