Skip to content

Instantly share code, notes, and snippets.

@tsycho
Last active December 15, 2015 21:49
Show Gist options
  • Save tsycho/5328714 to your computer and use it in GitHub Desktop.
Save tsycho/5328714 to your computer and use it in GitHub Desktop.
class OAuthController < ApplicationController
def authenticate
oauth_token = params[:oauth_token]
oauth_verifier = params[:oauth_verifier]
@user = User.find_by_oauth_token(oauth_token)
if !@user
# Do something appropriate, such as a 404
else
begin
oauth_tokens = get_access_token(oauth_token, @user.oauth_token_secret, oauth_verifier)
# Update @user, save oauth_tokens in the database (in a secure way)
rescue Exception => e
# Something went wrong, or user did not give you permissions on Gmail
# Do something appropriate, potentially try again?
flash[:error] = "There was an error while authenticating with Gmail. Please try again."
end
redirect_to root_url
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment