Configuring Torii is super simple. The only trick is that the name of the session conflicts with ember-simple-auth. I renamed mine to torii-session.

Calling this.get('torii').open('facebook-oauth2') triggers a Facbook dialog to show in another window. There may be a better way to get the token into simple auth but I wrote a synchronous method that calls some private APIs… don’t judge me.

Logging into Facebook triggers a postMessage to notify Torii of success or failure. Torii then POSTs the code to your backend using the adapter.

The adapter is simple enough to mock with ember-cli-mirage. I just return a token if the parameters exist.

The more challenging part (usually) is stubbing the Facebook authentication. Here is what I wanted to write:

Notice how ember-cli-page-object make the tests read so pretty!

Not surprisingly, Ember’s dependency injection and some great patterns in Torii make swapping the original facebook-oauth2 service for our stubbed service straight forward.

Today I Learned is an open-source project by
Hashrocket
that exists to catalogue the sharing & accumulation of knowledge
as it happens day-to-day. Posts have a 200-word limit, and
posting is open to any Rocketeer as well as selected friends of
Hashrocket. We hope you enjoy learning along with us.