Omniauth and OAuth in Ruby


Omniauth is a library that standardizes authentication for web applications. It allows you to add different sign-in methods with ease. Sign-ins are known as strategies. A strategy can be Twitter via OAuth 2 protocol or it could be LDAP Omniauth strategies are usually released as gems but you can also write your own if the gem doesn't exist for the authentication system that is being implemented.

There are all kinds of different gems out there. You just need to find one that would work with your application. There are usually instructions within the github.

To add the gem to your application all you would do is find a gem that is compatible and add it to your gem file. And then run bundle install. Next you would need to tell Omniauth that you are using twitter. to do that all you would need to do is add an Omniauth file under initializers.

Above you can see the placeholders for the API Key and API Secret. Those credentials will be supplied by the application that we will be authenticating against. It would be Twitter in this case.

Twitter allows us to create a new app or we can grab the key and secret from an existing application.

Under key and access tokens there is the API key and theres a secret.

Once this has been done within your home page add a link to sign in within your application using Twitter like below.

Once this has been done once the link is clicked it will take you to twitter to authenticate. Once you sign in within Twitter you are good to go.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store