Created
March 3, 2014 14:02
-
-
Save jrhe/9325535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Facebook from 'appkit/initializers/facebook'; | |
var FacebookAuthenticator = Ember.SimpleAuth.Authenticators.OAuth2.extend({ | |
authenticate: function() { | |
var _this = this; | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
FB.getLoginStatus(function(response) { | |
if (response.status === 'connected') { | |
_this.facebookCallback().then(function(response) { | |
var expiresAt = _this.absolutizeExpirationTime(response.expires_in); | |
_this.scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token); | |
resolve(Ember.$.extend(response, { expires_at: expiresAt })); | |
}); | |
} else if (response.status === 'unauthorized') { | |
reject("YOU ARE UNAUTHORIZED"); | |
} else { | |
FB.login(function(response) { | |
if (response.authResponse) { | |
_this.facebookCallback().then(function(response) { | |
var expiresAt = _this.absolutizeExpirationTime(response.expires_in); | |
_this.scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token); | |
resolve(Ember.$.extend(response, { expires_at: expiresAt })); | |
}); | |
} else { | |
reject("Could not login to facebook."); | |
} | |
}); | |
} | |
}); | |
}); | |
}, | |
facebookCallback: function() { | |
return ic.ajax('/api/auth/facebook/callback'); | |
} | |
}); | |
export default FacebookAuthenticator; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment