Skip to content

Instantly share code, notes, and snippets.

@eddygarcas
Last active March 14, 2022 18:43
Show Gist options
  • Save eddygarcas/4b52e588c90e38c9fa944dfe0cb2840d to your computer and use it in GitHub Desktop.
Save eddygarcas/4b52e588c90e38c9fa944dfe0cb2840d to your computer and use it in GitHub Desktop.
Trello OAuth 1.0 authorization with Ruby
#Add this routes.rb file
# get '/oauth', to: 'trello_sessions#new'
# get '/oauth/authorize', to: 'trello_sessions#authorize', as:'oauth_authorize'
class TrelloSessionsController < ApplicationController
def new
request_token = trello_consumer.get_request_token(:oauth_callback => oauth_authorize_url)
session[:token] = request_token.token
session[:token_secret] = request_token.secret
redirect_to request_token.authorize_url(:scope => :read,:name => "You app name")
end
def authorize
access_token = trello_consumer.get_request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
session[:trello_auth] = {
:oauth_token => access_token.token,
:oauth_token_secret => access_token.secret
}
redirect_to root_path
end
private
def trello_consumer
#Both consumer elements from https://trello.com/app-key
OAuth::Consumer.new(
"YOUR_CONSUMER_KEY",
"YOUR_CONSUMER_SECRET",
{
:site => "https://trello.com",
:http_method => :get,
:debug_output => true,
:request_token_path => "/1/OAuthGetRequestToken",
:access_token_path => "/1/OAuthGetAccessToken",
:authorize_path => "/1/OAuthAuthorizeToken"
})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment