handle change in scope

This commit is contained in:
Morgan McMillian 2018-02-20 20:42:42 -08:00
parent e55fafe04b
commit 1c9dafa4e3
3 changed files with 23 additions and 9 deletions

View file

@ -21,6 +21,8 @@ export class MyApp {
pages: Array<{title: string, component: any, params: Object}>;
scope: Array<string> = ['basic','stream','write_post','files'];
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen,
private storage: Storage, private device: Device) {
this.initializeApp();
@ -67,11 +69,22 @@ export class MyApp {
this.storage.get('token').then((val) => {
if (val.length > 1) {
pnut.token = val;
this.nav.setRoot(StreamPage, {stream: timeline});
this.storage.get('scope').then((sval) => {
if (JSON.stringify(sval) !== JSON.stringify(this.scope)) {
this.nav.setRoot(LoginPage, {'scope': this.scope});
} else {
this.nav.setRoot(StreamPage, {stream: timeline});
}
// this.nav.setRoot(StreamPage, {stream: timeline});
}).catch(err => {
this.nav.setRoot(LoginPage, {'scope': this.scope});
});
// this.nav.setRoot(StreamPage, {stream: timeline});
}
}).catch(err => {
console.log('ERROR: ' + err);
this.nav.setRoot(LoginPage);
this.nav.setRoot(LoginPage, {'scope': this.scope});
});
}
@ -81,7 +94,7 @@ export class MyApp {
if (page.title === 'Logout') {
// this.storage.remove('token');
this.storage.clear();
this.nav.setRoot(LoginPage);
this.nav.setRoot(LoginPage, {'scope': this.scope});
} else if (page.title === 'Settings') {
this.nav.push(page.component, page.params);
} else {

View file

@ -26,28 +26,29 @@ export class LoginPage {
private oob: boolean = false;
public showToken: boolean = false;
private token: string;
private scope: Array<string> = [];
constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage,
private device: Device) {
let scope = ['basic','stream','write_post','files'];
this.scope = navParams.data.scope;
if (this.device.platform === "Android" || this.device.platform === "amazon-fireos") {
this.oauth = new OauthCordova();
this.pnutProvider = new PnutAuth({
appScope: scope,
appScope: this.scope,
redirectUri: 'http://localhost/callback'
});
} else if (this.device.platform === "blackberry10") {
this.oauth = new OauthBrowser();
this.pnutProvider = new PnutAuth({
appScope: scope,
appScope: this.scope,
redirectUri: 'https://zoidberg.monkeystew.net/'
});
} else {
this.oauth = new OauthBrowser();
this.pnutProvider = new PnutAuth({
appScope: scope,
appScope: this.scope,
redirectUri: 'urn:ietf:wg:oauth:2.0:oob'
});
this.oob = true;
@ -59,6 +60,7 @@ export class LoginPage {
this.oauth.logInVia(this.pnutProvider).then(success => {
console.log('RESULT: ' + JSON.stringify(success));
this.storage.set('token', success['access_token']);
this.storage.set('scope', this.scope);
pnut.token = success['access_token'];
this.navCtrl.setRoot(StreamPage, {stream: 'personal'});
}, error => {
@ -70,6 +72,7 @@ export class LoginPage {
}
saveToken() {
this.storage.set('scope', this.scope);
this.storage.set('token', this.token);
pnut.token = this.token;
this.navCtrl.setRoot(StreamPage, {stream: 'personal'});

View file

@ -167,8 +167,6 @@ export class StreamPage {
count: 40
};
this.fetcher(params).then(res => {
console.log('-fetch success-');
console.log(JSON.stringify(res));
if (res.meta.code === 401) {
this.storage.clear();
this.navCtrl.setRoot(LoginPage);