Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d88106d
Update OmniAuth repo URL and minor spelling tweaks
Nov 11, 2016
082658d
Update README.md
nchelluri Nov 21, 2016
c628406
Drop json gem support
arunagw Dec 23, 2016
1d7161a
Use 2.4 on travis
arunagw Dec 23, 2016
de237dd
Add rack as dependency
unasuke Jan 6, 2017
c16566e
Drop support on eol ruby versions
unasuke Jan 6, 2017
d4cc40d
Specify patch version of rubies on travis
unasuke Jan 6, 2017
3070898
Install rack 1.6 if ruby version is lower than 2.2.2
unasuke Jan 6, 2017
a6765c9
Install addressable 2.4.0 if ruby version is lower than 2.0.0
unasuke Jan 6, 2017
ecbd65f
Specify distro in travis to ubuntu:trusty(14.04)
unasuke Jan 6, 2017
3c42573
Drop support of rubinius
unasuke Jan 6, 2017
1ed5f66
Merge pull request #114 from unasuke/drop_eol_ruby
raysrashmi Jan 11, 2017
74cc5ca
version bump to 1.3.0
raysrashmi Jan 11, 2017
4b6122a
Override the `callback_path` method
bzf Aug 22, 2016
7d066d1
Call parent class callback_url when params[‘callback_url’] is nil
raysrashmi Feb 3, 2017
e83ff39
Merge pull request #107 from bzf/al-allow-custom-callback-url
raysrashmi Feb 7, 2017
b82964c
Bump new version 1.4.0
raysrashmi Feb 7, 2017
bbb38cb
[CI] Test against Ruby 2.5
nicolasleger Feb 22, 2018
32dcc73
Merge pull request #124 from nicolasleger/patch-1
arunagw Feb 22, 2018
c010473
Merge pull request #110 from vassyz/patch-1
arunagw Feb 22, 2018
e3e61e0
Update Twitter doc link
arunagw Apr 18, 2018
3e9ca35
Merge pull request #127 from arunagw/fix-readme-link
arunagw Apr 23, 2018
9ef3ce3
Update Twitter doc links
arinco May 21, 2019
efb7796
Fix broken Twitter doc links in README
michaelrbock Jul 17, 2020
41c7be0
Merge pull request #136 from michaelrbock/patch-1
arunagw Jul 17, 2020
a61faf3
Move CI to GitHub Actions
jessieay May 25, 2023
386b41d
Update bundler
jessieay May 25, 2023
7cc2c11
Merge pull request #147 from jessieay/master
arunagw Jun 8, 2023
8fe3865
Merge pull request #111 from nchelluri/patch-1
arunagw Jun 8, 2023
22458f8
Add CHANGELOG
raysrashmi Jun 9, 2023
2d976b1
Update twitter docs link
raysrashmi Jul 21, 2023
3a807b1
Merge pull request #148 from arunagw/update_readme
raysrashmi Jul 21, 2023
aba1d0e
Merge pull request #149 from arunagw/add-changelog
arunagw Aug 8, 2023
ef888ab
Merge pull request #132 from arinco/fix-old-links
arunagw Aug 8, 2023
ebe0a4d
Update api.twitter.com to api.x.com because that's what they're wanti…
pgib Aug 6, 2024
4bd7572
Merge pull request #150 from Latermedia/update/twitter-dot-com-to-x-d…
raysrashmi Sep 8, 2024
becbb05
Improve CI
willnet Jun 17, 2025
6115fc8
Merge pull request #152 from willnet/add-ruby-3-3-and-3-4
arunagw Jul 9, 2025
8febaa3
Remove bundler as development_dependency from gemspec file
raysrashmi Jan 16, 2026
8d9eac7
Merge pull request #155 from arunagw/raysrashmi-remove-bundler-depend…
raysrashmi Jan 16, 2026
f08dd48
Add `ruby@4.0` to the CI matrix
seanpdoyle Jan 14, 2026
e898df6
Merge pull request #153 from seanpdoyle/ruby-4-0
raysrashmi Jan 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on: [push, pull_request]

jobs:
test:
strategy:
matrix:
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '4.0', 'jruby']
fail-fast: false
max-parallel: 10
runs-on: ubuntu-latest

env:
CI: true

name: ${{ matrix.ruby }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true # 'bundle install' and cache
ruby-version: ${{ matrix.ruby }}
- run: bundle exec rake
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CHANGELOG

## [1.4.0] - Feb 17, 2017
- Allow passing a callback_url param, see https://github.com/arunagw/omniauth-twitter/pull/107
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ new line in each of your commit messages:
[ci skip]
```

This will signal [Travis](https://travis-ci.org) that running the test suite is
not necessary for these changes.
This will signal [GitHub Actions](https://docs.github.com/en/actions) that running the test suite is not necessary for these changes.

# Reporting Bugs

Expand Down
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ gemspec
gem 'rake'

group :test do
if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.0.0")
# for jruby 1.7.x
gem "addressable", "2.4.0"
end

if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.2")
gem "rack", "~> 1.6"
end

gem 'rspec', '~> 3.2'
gem 'rack-test'
gem 'simplecov'
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# OmniAuth Twitter

[![Gem Version](https://badge.fury.io/rb/omniauth-twitter.svg)](http://badge.fury.io/rb/omniauth-twitter)
[![CI Build Status](https://secure.travis-ci.org/arunagw/omniauth-twitter.svg?branch=master)](http://travis-ci.org/arunagw/omniauth-twitter)
[![Code Climate](https://codeclimate.com/github/arunagw/omniauth-twitter.png)](https://codeclimate.com/github/arunagw/omniauth-twitter)

This gem contains the Twitter strategy for OmniAuth.

Twitter offers a few different methods of integration. This strategy implements the browser variant of the "[Sign in with Twitter](https://dev.twitter.com/docs/auth/implementing-sign-twitter)" flow.
Twitter offers a few different methods of integration. This strategy implements the browser variant of the "[Sign in with Twitter](https://dev.twitter.com/web/sign-in/implementing)" flow.

Twitter uses OAuth 1.0a. Twitter's developer area contains ample documentation on how it implements this, so check that out if you are really interested in the details.

## Before You Begin

You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started.
You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/omniauth/omniauth) to get started.

Now sign in into the [Twitter developer area](https://dev.twitter.com/apps) and create an application. Take note of your API Key and API Secret (not the Access Token and Access Token Secret) because that is what your web application will use to authenticate against the Twitter API. Make sure to set a callback URL or else you may get authentication errors. (It doesn't matter what it is, just that it is set.)

Expand Down Expand Up @@ -42,7 +41,7 @@ Replace `"API_KEY"` and `"API_SECRET"` with the appropriate values you obtained

## Authentication Options

Twitter supports a [few options](https://dev.twitter.com/docs/api/1/get/oauth/authenticate) when authenticating. Usually you would specify these options as query parameters to the Twitter API authentication url (`https://api.twitter.com/oauth/authenticate` by default). With OmniAuth, of course, you use `http://yourapp.com/auth/twitter` instead. Because of this, this OmniAuth provider will pick up the query parameters you pass to the `/auth/twitter` URL and re-use them when making the call to the Twitter API.
Twitter supports a [few options](https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate) when authenticating. Usually you would specify these options as query parameters to the Twitter API authentication URL (`https://api.x.com/oauth/authenticate` by default). With OmniAuth, of course, you use `http://yourapp.com/auth/twitter` instead. Because of this, this OmniAuth provider will pick up the query parameters you pass to the `/auth/twitter` URL and re-use them when making the call to the Twitter API.

The options are:

Expand All @@ -52,15 +51,15 @@ The options are:

* **lang** - The language used in the Twitter prompt. This is useful for adding i18n support since the language of the prompt can be dynamically set for each user. *Example:* `http://yoursite.com/auth/twitter?lang=pt`

* **secure_image_url** - Set to `true` to use https for the user's image url. Default is `false`.
* **secure_image_url** - Set to `true` to use https for the user's image URL. Default is `false`.

* **image_size**: This option defines the size of the user's image. Valid options include `mini` (24x24), `normal` (48x48), `bigger` (73x73) and `original` (the size of the image originally uploaded). Default is `normal`.

* **x_auth_access_type** - This option (described [here](https://dev.twitter.com/docs/api/1/post/oauth/request_token)) lets you request the level of access that your app will have to the Twitter account in question. *Example:* `http://yoursite.com/auth/twitter?x_auth_access_type=read`
* **x_auth_access_type** - This option (described [here](https://developer.twitter.com/en/docs/basics/authentication/api-reference/request_token)) lets you request the level of access that your app will have to the Twitter account in question. *Example:* `http://yoursite.com/auth/twitter?x_auth_access_type=read`

* **use_authorize** - There are actually two URLs you can use against the Twitter API. As mentioned, the default is `https://api.twitter.com/oauth/authenticate`, but you also have `https://api.twitter.com/oauth/authorize`. Passing this option as `true` will use the second URL rather than the first. What's the difference? As described [here](https://dev.twitter.com/docs/api/1/get/oauth/authenticate), with `authenticate`, if your user has already granted permission to your application, Twitter will redirect straight back to your application, whereas `authorize` forces the user to go through the "grant permission" screen again. For certain use cases this may be necessary. *Example:* `http://yoursite.com/auth/twitter?use_authorize=true`. *Note:* You must have "Allow this application to be used to Sign in with Twitter" checked in [your application's settings](https://dev.twitter.com/apps) - without it your user will be asked to authorize your application each time they log in.
* **use_authorize** - There are actually two URLs you can use against the Twitter API. As mentioned, the default is `https://api.x.com/oauth/authenticate`, but you also have `https://api.twitter.com/oauth/authorize`. Passing this option as `true` will use the second URL rather than the first. What's the difference? As described [here](https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate), with `authenticate`, if your user has already granted permission to your application, Twitter will redirect straight back to your application, whereas `authorize` forces the user to go through the "grant permission" screen again. For certain use cases this may be necessary. *Example:* `http://yoursite.com/auth/twitter?use_authorize=true`. *Note:* You must have "Allow this application to be used to Sign in with Twitter" checked in [your application's settings](https://dev.twitter.com/apps) - without it your user will be asked to authorize your application each time they log in.

Here's an example of a possible configuration where the the user's original profile picture is returned over https, the user is always prompted to sign-in and the default language of the Twitter prompt is changed:
Here's an example of a possible configuration where the user's original profile picture is returned over https, the user is always prompted to sign-in and the default language of the Twitter prompt is changed:

```ruby
Rails.application.config.middleware.use OmniAuth::Builder do
Expand All @@ -84,7 +83,7 @@ An example auth hash available in `request.env['omniauth.auth']`:
:provider => "twitter",
:uid => "123456",
:info => {
:nickname => "johnqpublic",
:nickname => "johnqpublic", # screen name
:name => "John Q Public",
:location => "Anytown, USA",
:image => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
Expand Down Expand Up @@ -117,7 +116,7 @@ An example auth hash available in `request.env['omniauth.auth']`:
:profile_sidebar_fill_color => "666666",
:followers_count => 1,
:default_profile_image => false,
:screen_name => "",
:screen_name => "johnqpublic",
:following => false,
:utc_offset => -3600,
:verified => false,
Expand Down Expand Up @@ -156,7 +155,9 @@ Ryan Bates has put together an excellent RailsCast on OmniAuth:

## Supported Rubies

OmniAuth Twitter is tested under 1.9.3, 2.0.0, 2.1.x, 2.2.x, JRuby, and Rubinius.
OmniAuth Twitter is tested under 2.1.x, 2.2.x and JRuby.

If you use its gem on ruby 1.9.x, 2.0.x, or Rubinius use version v1.2.1 .

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth-twitter/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module Twitter
VERSION = "1.2.1"
VERSION = "1.4.0"
end
end
20 changes: 18 additions & 2 deletions lib/omniauth/strategies/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Twitter < OmniAuth::Strategies::OAuth
option :name, 'twitter'

option :client_options, {:authorize_path => '/oauth/authenticate',
:site => 'https://api.twitter.com',
:site => 'https://api.x.com',
:proxy => ENV['http_proxy'] ? URI(ENV['http_proxy']) : nil}

uid { access_token.params[:user_id] }
Expand Down Expand Up @@ -61,8 +61,24 @@ def request_phase
old_request_phase
end

alias :old_callback_url :callback_url

def callback_url
request.params['callback_url'] || super
if request.params['callback_url']
request.params['callback_url']
else
old_callback_url
end
end

def callback_path
params = session['omniauth.params']

if params.nil? || params['callback_url'].nil?
super
else
URI(params['callback_url']).path
end
end

private
Expand Down
6 changes: 3 additions & 3 deletions omniauth-twitter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency 'json', '~> 1.3'
s.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
s.add_dependency 'omniauth-oauth', '~> 1.1'
s.add_development_dependency 'bundler', '~> 1.0'
s.add_dependency 'rack'
s.add_dependency 'cgi'
end
44 changes: 43 additions & 1 deletion spec/omniauth/strategies/twitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

it 'should have correct site' do
expect(subject.options.client_options.site).to eq('https://api.twitter.com')
expect(subject.options.client_options.site).to eq('https://api.x.com')
end

it 'should have correct authorize url' do
Expand Down Expand Up @@ -130,6 +130,48 @@
end
end

context 'with a specified callback_url in the params' do
before do
params = { 'callback_url' => 'http://foo.dev/auth/twitter/foobar' }
allow(subject).to receive(:request) do
double('Request', :params => params)
end
allow(subject).to receive(:session) do
double('Session', :[] => { 'callback_url' => params['callback_url'] })
end
allow(subject).to receive(:old_request_phase) { :whatever }
end

it 'should use the callback_url' do
expect(subject.callback_url).to eq 'http://foo.dev/auth/twitter/foobar'
end

it 'should return the correct callback_path' do
expect(subject.callback_path).to eq '/auth/twitter/foobar'
end
end

context 'with no callback_url set' do
before do
allow(subject).to receive(:request) do
double('Request', :params => {})
end
allow(subject).to receive(:session) do
double('Session', :[] => {})
end
allow(subject).to receive(:old_request_phase) { :whatever }
allow(subject).to receive(:old_callback_url).and_return(:old_callback)
end

it 'callback_url should return nil' do
expect(subject.callback_url).to eq :old_callback
end

it 'should return the default callback_path value' do
expect(subject.callback_path).to eq '/auth/twitter/callback'
end
end

context "with no request params set and force_login specified" do
before do
allow(subject).to receive(:request) do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$:.unshift File.expand_path('../../lib', __FILE__)
require 'simplecov'
SimpleCov.start do
minimum_coverage(94.59)
minimum_coverage(90)
end
require 'rspec'
require 'rack/test'
Expand Down