New Faker Gem Feature Announcement

I am excited to announce that my contribution to the Faker Gem has been accepted and is now available to the public with:

gem install faker

The Faker Gem is a widely used fake data generation library in the Ruby community. According to RubyGems, as of this writing, it has over 12.6 million downloads. It is a library I have used on many projects for creating fake names for products, customers, fake dates, and even fake hipster copy. I was eager to contribute to this open source tool and I stumbled upon a feature request for something I know a fair bit about - omniauth.

The request was to build a module that could create fake omniauth hashes. Omniauth is a library that standardizes multi-provider authentication for web applications. It is what allows a user to sign into a web application with user credentials from another application, like Twitter or Facebook.

To understand what an Omniauth hash is, lets first think about what happens when you click a "Login with Facebook" button in some application. At a high level, the host application is sending a request to Facebook that says, "Hey, this person wants to sign in to our application. Can you (Facebook) verify that they are who they are for us?" Upon clicking the sign in button, the user is directed to a Facebook page.


At that point, Facebook says, "Hey, user, this application is asking if I know you. Do you want me to say that I know you?" When the user clicks 'Continue', Facebook, then sends the user back to the original application along with some user data. Facebook is saying, "Hey application, this person is cool, you should let them sign in. Here is their information."

Omniauth hashes are the data sent back to the original application by Facebook, Google, Twitter, LinkedIn, and any number of other Oauth providers. The data looks different depending on the Oauth provider. It is annoying to create this data for testing purposes because doing so requires looking through documentation for each individual Oauth provider.

Enter my contribution to the Faker Gem!

Once you've installed the latest version of the Gem, you get access to a module called:


The Omniauth module has four methods:

Calling any of the above methods will randomly generate a fake Omniauth hash based on the specifications of that specific OAuth provider. This is meant to help ease the burden of testing your login features.

Here is an example of the facebook hash: 

Faker::Omniauth.facebook #=>
   provider: 'facebook',
   uid: '1234567',
   info: {
     email: '',
     name: 'Joe Bloggs',
     first_name: 'Joe',
     last_name: 'Bloggs',
     image: '',
     verified: true
   credentials: {
     token: 'ABCDEF...',
     expires_at: 1321747205,
     expires: true
   extra: {
     raw_info: {
       id: '1234567',
       name: 'Joe Bloggs',
       first_name: 'Joe',
       last_name: 'Bloggs',
       link: '',
       username: 'jbloggs',
       location: { id: '123456789', name: 'Palo Alto, California' },
       gender: 'male',
       email: '',
       timezone: -8,
       locale: 'en_US',
       verified: true,
       updated_time: '2011-11-11T06:21:03+0000',

You can checkout examples of all of the fake hashes on Faker's documentation. You can learn more about Omniauth here. If you want to take a look under the hood and see how I am creating these hashes, you can see the merged pull request here.

I am very excited to be a contributing member of the Faker Gem community and I encourage all of you to take some time to contribute to Faker and your other favorite open source projects. Open Source is a powerful political statement and in times like these all of our actions count!