Skip to content

Conversation

@AgoraSecurity
Copy link

Solve issue #161

SUMMARY

  1. Adds authenticate_url methods.
  2. Bumps version number

VERIFICATION

I did some testing and it works.

Very simple code to verify:

#!/usr/bin/ruby
require 'oauth'
require 'sinatra'

CONSUMER_KEY = ENV['CONSUMER_KEY']
CONSUMER_SECRET = ENV['CONSUMER_SECRET']

raise 'Missing Consumer' if CONSUMER_KEY.nil? || CONSUMER_SECRET.nil?

set :port, 8000
set :bind, '0.0.0.0'

consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, site: 'https://api.twitter.com')

get '/' do
  "Hello World!"
end

get '/register' do
  request_token = consumer.get_request_token oauth_callback: 'https://twitter-test.agora-security.com/auth/twitter/callback'
  redirect request_token.authorize_url
end

get '/login' do
  request_token = consumer.get_request_token oauth_callback: 'https://twitter-test.agora-security.com/auth/twitter/callback'
  redirect request_token.authenticate_url
end

get '/auth/twitter/callback' do
  # Using https://developer.twitter.com/en/docs/twitter-for-websites/log-in-with-twitter/guides/implementing-sign-in-with-twitter
  # Step 1 - First request
  request_token = consumer.get_request_token oauth_callback: 'https://twitter-test.agora-security.com/auth/twitter/callback'
  # Step 2 - Receive callback
  request_token.token = params["oauth_token"]
  # Step 3 - Converting the request token to an access token
  access_token = request_token.get_access_token(:oauth_verifier => params["oauth_verifier"])
  username = access_token.params.dig 'screen_name'
  timestamp = Time.now.to_i
  params = access_token.params
  status 200
  body "Welcome #{username}. You are logged in :)"
end

Note: The code to verify, requires that you have a Twitter App, a domain and your app configured with the proper call back URL.

@AgoraSecurity
Copy link
Author

Can't easily fix "Class has too many lines. [257/250]". I suggest that is ignored for now.

If required, I could refactor that file.

@AgoraSecurity
Copy link
Author

@quirkey I would love your feedback when you have a chance.

@AgoraSecurity
Copy link
Author

@pboling I would love your feedback when you have a chance.

Copy link
Member

@pboling pboling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me!

@pboling pboling merged commit 200b109 into ruby-oauth:master Dec 26, 2019
@AgoraSecurity AgoraSecurity deleted the add_authorize branch January 10, 2021 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants