Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
firebaseAuthConfig,
AuthProviders,
AuthMethods
} from 'angularfire2';
@App({
templateUrl: 'build/app.html',
config: {}, // http://ionicframework.com/docs/v2/api/config/Config/
providers: [
Story,
User,
Beacons,
FIREBASE_PROVIDERS,
defaultFirebase('https://aofs.firebaseio.com/'),
firebaseAuthConfig({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup,
remember: 'default',
scope: ['email']
})
]
})
class MyApp {
// make HelloIonicPage the root (or first) page
rootPage: any = Start;
pages: Array<{ title: string, component: any }>;
constructor(
private app: IonicApp,
private platform: Platform,
private menu: MenuController
) {
public doLogin() {
var start = this;
// This will perform popup auth with google oauth and the scope will be email
// Because those options were provided through bootstrap to DI, and we're overriding the provider.
this.auth.login({
provider: AuthProviders.Facebook
}).then(function(value) {
start.firebaseAuthState = value;
});;
}
public doLogout() {
let provider = firebase.auth.FacebookAuthProvider.credential(facebookData.authResponse.accessToken);
firebase.auth().signInWithCredential(provider).then(firebaseData => {
this.af.database.list('users').update(firebaseData.uid, {
name: firebaseData.displayName,
email: firebaseData.email,
provider: 'facebook',
image: firebaseData.photoURL
});
observer.next();
});
}, error => {
observer.error(error);
});
} else {
this.af.auth.login({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup
}).then((facebookData) => {
this.af.database.list('users').update(facebookData.auth.uid, {
name: facebookData.auth.displayName,
email: facebookData.auth.email,
provider: 'facebook',
image: facebookData.auth.photoURL
});
observer.next();
}).catch((error) => {
console.info("error", error);
observer.error(error);
});
}
});
}
login() {
this.af.auth.login({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup
})
}
private _getProvider(from: string) {
switch(from){
case 'twitter': return AuthProviders.Twitter;
case 'facebook': return AuthProviders.Facebook;
case 'github': return AuthProviders.Github;
case 'google': return AuthProviders.Google;
}
}
}
(dialog: MatDialog, af: AngularFire, dRef: MatDialogRef) => {
let spy = spyOn(af.auth, "login");
fixture.detectChanges();
let deButtons = fixture.debugElement.queryAll(By.css('button'));
deButtons[0].triggerEventHandler('click', null);
expect(af.auth.login).toHaveBeenCalled();
expect(spy.calls.mostRecent().args[0].provider).toBe(AuthProviders.Google, 'Provider Google');
expect(spy.calls.mostRecent().args[0].method).toBe(AuthMethods.Popup, 'Method Popup');
deButtons[1].triggerEventHandler('click', null);
expect(af.auth.login).toHaveBeenCalled();
expect(spy.calls.mostRecent().args[0].provider).toBe(AuthProviders.Facebook, 'Provider Facebook');
expect(spy.calls.mostRecent().args[0].method).toBe(AuthMethods.Popup, 'Method Popup');
deButtons[2].triggerEventHandler('click', null);
expect(af.auth.login).toHaveBeenCalled();
expect(spy.calls.mostRecent().args[0].provider).toBe(AuthProviders.Twitter, 'Provider Twitter');
expect(spy.calls.mostRecent().args[0].method).toBe(AuthMethods.Popup, 'Method Popup');
deButtons[3].triggerEventHandler('click', null);
expect(af.auth.login).toHaveBeenCalled();
expect(spy.calls.mostRecent().args[0].provider).toBe(AuthProviders.Github, 'Provider Github');
expect(spy.calls.mostRecent().args[0].method).toBe(AuthMethods.Popup, 'Method Popup');
let spy2 = spyOn(dialog, "open")
.and.callFake((type: any, options: any) => {
expect(typeof type).toEqual("function");
expect(options.disableClose).toEqual(false);
private signInWithFacebook() {
if (!this.platform.is('cordova'))
return this.signInWithProvider(AuthProviders.Facebook);
return Facebook.login(['email', 'public_profile'])
.then(res => {
return this.signInWithCredential(firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken));
}, (error) => Promise.reject(error));
}
getAuthProvider(provider: string): {} {
var authProvider = {method: AuthMethods.Redirect};
switch (provider){
case 'Google': authProvider['provider'] = AuthProviders.Google; break;
case 'Github': authProvider['provider'] = AuthProviders.Github; break;
case 'Facebook': authProvider['provider'] = AuthProviders.Facebook; break;
case 'Twitter': authProvider['provider'] = AuthProviders.Twitter; break;
default: return '{}';
}
return authProvider;
}