Skip to content

Commit

Permalink
removed $timeout from oauth2, fixed cordova issue with oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
sahat committed Aug 30, 2016
1 parent db08802 commit 6291241
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions src/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,32 @@ export default class OAuth2 {
init(options: IOAuth2Options, userData: any): angular.IPromise<any> {
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<any>|angular.IHttpPromise<any> => {
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<any>|angular.IHttpPromise<any> => {
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));
});
}

Expand Down

0 comments on commit 6291241

Please sign in to comment.