Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Created November 16, 2012 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NullVoxPopuli/4087759 to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/4087759 to your computer and use it in GitHub Desktop.
How TinderBox authenticates users via oAuth for using RightSignature
# start with being logged out of right signature or
# logged in as the user that we are going to allow TinderBox with
def set_up_right_signature_oauth
@subscription = Subscription.find(params[:id])
@account = @subscription.account
# get the master/consumer/app credentials
cred = IntegrationsConfig["right_signature"]
# find / generate the client's / account's consumer key/secret pair
consumer_key = cred["o_auth_key"]
consumer_secret = cred["o_auth_secret"]
# create an oAuth connection
rs = RightSignature::OauthConnection.new(:consumer_secret => consumer_secret, :consumer_key => consumer_key)
# request a token
# this will generate a URL that we'll need to go to to actually authorize the
# usage of tinderbok through.
r = rs.new_request_token(:oauth_callback => "http://admin.tinderbox.vhost/subscriptions/right_signature_oauth_callback/#{params[:id]}")
redirect_to r.authorize_url
# save the client / account secret/key pair in their integration record.
# also store the connection itself so that we can contiue authenticating when
# RightSignature calls back to us.
@account.integrations[ESignature::RIGHT_SIGNATURE] = {
:consumer_secret => consumer_secret,
:consumer_key => consumer_key,
:connection => rs
}
end
def right_signature_oauth_callback
@subscription = Subscription.find(params[:id])
@account = @subscription.account
config = @account.integrations[ESignature::RIGHT_SIGNATURE].config
# retreive the oAuth connection f rom the config
rs = @account.integrations[ESignature::RIGHT_SIGNATURE].config[:connection]
# generate the access token/secret pair
rs.generate_access_token(params[:oauth_verifier])
# create a connection to RightSignature with all of the oAuth credentials
rsc = RightSignature::Connection.new({
:consumer_key => config[:consumer_key],
:consumer_secret => config[:consumer_secret],
:access_token => rs.access_token.token,
:access_secret => rs.access_token.secret
})
# store all of the credentials in the integration config
# along with a flag saying that we have successfully completed
# authorizing via oAuth.
config = @account.integrations[ESignature::RIGHT_SIGNATURE] = config.merge({
:access_token => rs.access_token.token,
:access_secret => rs.access_token.secret,
:has_credentials => rsc.has_oauth_credentials?
})
redirect_to :action => :show, :id => @subscription[:id]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment