facebookauthenticationember.jsfirebasetorii

Append firebase JWT in Ember-simple-auth


I am trying to do authorization in my Ember App(2.10). My workflow is

  1. user hit the button of Facebook login then
  2. i'm using torii to get the access token /my user database is on firebase/
  3. Then i send token to firebase.auth with facebook provider. It returns JWT token.

Problem is i got the JWT token and now i have to login to my emberapp. I am trying to customize torii authenticator here. How can i implement this in ember app. Below is my authenticator:

authenticate() {
return this._super(...arguments).then((torii) => {
    const serverTokenEndpoint = this.get('serverTokenEndpoint');
    return this.get('ajax').request(serverTokenEndpoint, {
        type: 'POST',
        data: {
        'type': torii.provider,
        'client_id': this.client,
        'token': torii.authorizationCode
        }
    }).then((token) => {
        var provider = new firebase.auth.FacebookAuthProvider();
        firebase.auth().signInWithPopup(provider).then(function(result) {
        // This gives Facebook Access Token.
        // JWT-token=result.user.Cd
        // JWT-token.iat at=result.user.ea.Sa
        // JWT-token-refresh = result.user.refreshToken
        console.log(result)
        //   token = result.user.Cd;
        // const expiresAt = this._absolutizeExpirationTime(result.user.ea.Sa);
        token = Ember.assign(token, { 'expires_at': result.user.ea.Sa });
        // this._scheduleAccessTokenRefresh(result.user.ea.Sa, expiresAt, result.user.refreshToken, torii);
        return Ember.assign(token, {'torii': torii});
        });
    });
    });  
}

Solution

  • Check out this guide in the ESA repo. It covers torii and Github auth but the general concepts are the same for your use case.