Using OAuth2 gem

oauth2 - A Ruby wrapper for the OAuth 2.0 specification. gem install oauth2 Basics of OAuth2 is well explained here: Oauth2 basics Creating OAuth2::Client instance require 'oauth2' client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org') OAuth2 provides four authentication grant types : Authorization Code Grant Implicit Grant Resource Owner Password Credentials Grant Client Credentials Grant In UN project, we have used Resource Owner Password Credentials Grant type token = client.password.get_token('username', 'password') In case if Credentials are not correct, OAuth2::Error will be raised. With correct credentials, it gives OAuth2::AccessToken instance which