omniauth-firmafon 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3320b85eaea825551a6fc8d1574dd3cbb84ff329
4
+ data.tar.gz: 6f707f8324e77c21ca64d2363b3a53e9fe6e0c3a
5
+ SHA512:
6
+ metadata.gz: 576e532f16eac01068582ecd3dc43b1afebba0db4df945b23d417ef222e5075c30517b66f2cadd6976b5d4e2783b8ffcd3e4e6edd79d14da3ce4245fa0fb185b
7
+ data.tar.gz: 789f815ffac83b272fdb7c04c66abc2595b8d7f27c18fe805fde01a20880dde7c6d413eff58a61bb7e73b90eff3f23b3c3302d0b5b4cb0e22c3d298e51369a35
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-twitter.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # OmniAuth Twitter
2
+
3
+ This gem contains the Twitter strategy for OmniAuth.
4
+
5
+ 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.
6
+
7
+ Twitter uses OAuth 1.0a. Twitter's developer area contains ample documentation on how it implements this, so if you are really interested in the details, go check that out for more.
8
+
9
+ ## Before You Begin
10
+
11
+ You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started.
12
+
13
+ Now sign in into the [Twitter developer area](http://dev.twitter.com) and create an application. Take note of your Consumer Key and Consumer Secret (not the Access Token and 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.)
14
+
15
+ ## Using This Strategy
16
+
17
+ First start by adding this gem to your Gemfile:
18
+
19
+ ```ruby
20
+ gem 'omniauth-twitter'
21
+ ```
22
+
23
+ If you need to use the latest HEAD version, you can do so with:
24
+
25
+ ```ruby
26
+ gem 'omniauth-twitter', :github => 'arunagw/omniauth-twitter'
27
+ ```
28
+
29
+ Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
30
+
31
+ ```ruby
32
+ Rails.application.config.middleware.use OmniAuth::Builder do
33
+ provider :twitter, "CONSUMER_KEY", "CONSUMER_SECRET"
34
+ end
35
+ ```
36
+
37
+ Replace CONSUMER_KEY and CONSUMER_SECRET with the appropriate values you obtained from dev.twitter.com earlier.
38
+
39
+ ## Authentication Options
40
+
41
+ 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.
42
+
43
+ The options are:
44
+
45
+ * **force_login** - This option sends the user to a sign-in screen to enter their Twitter credentials, even if they are already signed in. This is handy when your application supports multiple Twitter accounts and you want to ensure the correct user is signed in. *Example:* `http://yoursite.com/auth/twitter?force_login=true`
46
+
47
+ * **screen_name** - This option implies **force_login**, except the screen name field is pre-filled with a particular value. *Example:* `http://yoursite.com/auth/twitter?screen_name=jim`
48
+
49
+ * **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`
50
+
51
+ * **secure_image_url** - Set to `true` to use https for the user's image url. Default is `false`.
52
+
53
+ * **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`.
54
+
55
+ * **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`
56
+
57
+ * **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.
58
+
59
+ 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:
60
+
61
+ ```ruby
62
+ Rails.application.config.middleware.use OmniAuth::Builder do
63
+ provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"],
64
+ {
65
+ :secure_image_url => 'true',
66
+ :image_size => 'original',
67
+ :authorize_params => {
68
+ :force_login => 'true',
69
+ :lang => 'pt'
70
+ }
71
+ }
72
+ end
73
+ ```
74
+
75
+ ## Authentication Hash
76
+ An example auth hash available in `request.env['omniauth.auth']`:
77
+
78
+ ```ruby
79
+ {
80
+ :provider => "twitter",
81
+ :uid => "123456",
82
+ :info => {
83
+ :nickname => "johnqpublic",
84
+ :name => "John Q Public",
85
+ :location => "Anytown, USA",
86
+ :image => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
87
+ :description => "a very normal guy.",
88
+ :urls => {
89
+ :Website => nil,
90
+ :Twitter => "https://twitter.com/johnqpublic"
91
+ }
92
+ },
93
+ :credentials => {
94
+ :token => "a1b2c3d4...", # The OAuth 2.0 access token
95
+ :secret => "abcdef1234"
96
+ },
97
+ :extra => {
98
+ :access_token => "", # An OAuth::AccessToken object
99
+ :raw_info => {
100
+ :name => "John Q Public",
101
+ :listed_count => 0,
102
+ :profile_sidebar_border_color => "181A1E",
103
+ :url => nil,
104
+ :lang => "en",
105
+ :statuses_count => 129,
106
+ :profile_image_url => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
107
+ :profile_background_image_url_https => "https://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
108
+ :location => "Anytown, USA",
109
+ :time_zone => "Chicago",
110
+ :follow_request_sent => false,
111
+ :id => 123456,
112
+ :profile_background_tile => true,
113
+ :profile_sidebar_fill_color => "666666",
114
+ :followers_count => 1,
115
+ :default_profile_image => false,
116
+ :screen_name => "",
117
+ :following => false,
118
+ :utc_offset => -3600,
119
+ :verified => false,
120
+ :favourites_count => 0,
121
+ :profile_background_color => "1A1B1F",
122
+ :is_translator => false,
123
+ :friends_count => 1,
124
+ :notifications => false,
125
+ :geo_enabled => true,
126
+ :profile_background_image_url => "http://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
127
+ :protected => false,
128
+ :description => "a very normal guy.",
129
+ :profile_link_color => "2FC2EF",
130
+ :created_at => "Thu Jul 4 00:00:00 +0000 2013",
131
+ :id_str => "123456",
132
+ :profile_image_url_https => "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
133
+ :default_profile => false,
134
+ :profile_use_background_image => false,
135
+ :entities => {
136
+ :description => {
137
+ :urls => []
138
+ }
139
+ },
140
+ :profile_text_color => "666666",
141
+ :contributors_enabled => false
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ## Watch the RailsCast
148
+
149
+ Ryan Bates has put together an excellent RailsCast on OmniAuth:
150
+
151
+ [![RailsCast #241](http://railscasts.com/static/episodes/stills/241-simple-omniauth-revised.png "RailsCast #241 - Simple OmniAuth (revised)")](http://railscasts.com/episodes/241-simple-omniauth-revised)
152
+
153
+ ## Supported Rubies
154
+
155
+ OmniAuth Twitter is tested under 1.8.7, 1.9.2, 1.9.3, 2.0.0, and Ruby Enterprise Edition.
156
+
157
+ [![CI Build
158
+ Status](https://secure.travis-ci.org/arunagw/omniauth-twitter.png)](http://travis-ci.org/arunagw/omniauth-twitter)
159
+
160
+ ## Note on Patches/Pull Requests
161
+
162
+ - Fork the project.
163
+ - Make your feature addition or bug fix.
164
+ - Add tests for it. This is important so I don’t break it in a future version unintentionally.
165
+ - Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
166
+ - Send me a pull request. Bonus points for topic branches.
167
+
168
+ ## License
169
+
170
+ Copyright (c) 2011 by Arun Agrawal
171
+
172
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
173
+
174
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
175
+
176
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-firmafon/version"
2
+ require 'omniauth/strategies/firmafon'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Firmafon
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Firmafon < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, :firmafon
8
+ option :provider_ignores_state, true
9
+
10
+ option :client_options, {
11
+ :site => 'https://app.firmafon.dk',
12
+ :authorize_url => '/api/v2/authorize',
13
+ :token_url => '/api/v2/token',
14
+ :provider_ignores_state => true
15
+ }
16
+
17
+ uid { raw_info['id'] }
18
+
19
+ info do
20
+ {
21
+ :id => raw_info['id'],
22
+ :name => raw_info['name']
23
+ }
24
+ end
25
+
26
+ extra do
27
+ raw_info
28
+ end
29
+
30
+ def raw_info
31
+ @raw_info ||= access_token.get('/api/v2/employee.json').parsed['employee']
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-firmafon/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-firmafon"
7
+ s.version = OmniAuth::Firmafon::VERSION
8
+ s.authors = ["Mikkel Malmberg"]
9
+ s.email = ["mm@firmafon.dk"]
10
+ s.homepage = "https://github.com/firmafon/omniauth-firmafon"
11
+ s.summary = %q{OmniAuth strategy for Firmafon}
12
+ s.description = %q{OmniAuth strategy for Firmafon}
13
+ s.license = "MIT"
14
+
15
+ s.rubyforge_project = "omniauth-firmafon"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.0.2'
23
+
24
+ s.add_development_dependency 'rspec', '~> 2.7'
25
+ s.add_development_dependency 'rake'
26
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Firmafon do
4
+
5
+ let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
6
+ let(:app) { lambda { |*args| [200, {}, ["Hello"]] } }
7
+
8
+ subject do
9
+ OmniAuth::Strategies::Firmafon.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
10
+ allow(strategy).to receive(:request) { request }
11
+ end
12
+ end
13
+
14
+ before do
15
+ OmniAuth.config.test_mode = true
16
+ end
17
+
18
+ after do
19
+ OmniAuth.config.test_mode = false
20
+ end
21
+
22
+ describe '#client_options' do
23
+ it 'has correct site' do
24
+ expect(subject.client.site).to eq('https://app.firmafon.dk')
25
+ end
26
+
27
+ it 'has correct authorize_url' do
28
+ expect(subject.client.options[:authorize_url]).to eq('/api/v2/authorize')
29
+ end
30
+
31
+ it 'has correct token_url' do
32
+ expect(subject.client.options[:token_url]).to eq('/api/v2/token')
33
+ end
34
+ end
35
+
36
+ describe "#callback_path" do
37
+ it 'has the correct callback path' do
38
+ subject.callback_path.should eq('/auth/firmafon/callback')
39
+ end
40
+ end
41
+
42
+ describe "#uid" do
43
+ before do
44
+ subject.stub(:raw_info) { { 'id' => 1 } }
45
+ end
46
+ it "is the id" do
47
+ expect(subject.uid).to eq(1)
48
+ end
49
+ end
50
+
51
+ describe "#info" do
52
+ before do
53
+ subject.stub(:raw_info) { {'id' => 1, 'name' => 'Karsten Kollega' } }
54
+ end
55
+ it "is the id" do
56
+ expect(subject.info).to eq({:id => 1, :name => 'Karsten Kollega' })
57
+ end
58
+ end
59
+
60
+ describe "#extra" do
61
+ before do
62
+ subject.stub(:raw_info) { { :foo => 'bar' } }
63
+ end
64
+ it { subject.extra.should eq({ :foo => 'bar'}) }
65
+ end
66
+
67
+ describe "#credentials" do
68
+ before do
69
+ @access_token = double('OAuth2::AccessToken').as_null_object
70
+ subject.stub(:access_token) { @access_token }
71
+ end
72
+
73
+ it 'returns the token' do
74
+ @access_token.stub(:token) { '123' }
75
+ subject.credentials['token'].should eq('123')
76
+ end
77
+ end
78
+
79
+ end
80
+
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require :default, :test
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-firmafon
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mikkel Malmberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: OmniAuth strategy for Firmafon
56
+ email:
57
+ - mm@firmafon.dk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - lib/omniauth-firmafon.rb
67
+ - lib/omniauth-firmafon/version.rb
68
+ - lib/omniauth/strategies/firmafon.rb
69
+ - omniauth-firmafon.gemspec
70
+ - spec/omniauth/strategies/firmafon_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: https://github.com/firmafon/omniauth-firmafon
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project: omniauth-firmafon
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: OmniAuth strategy for Firmafon
96
+ test_files:
97
+ - spec/omniauth/strategies/firmafon_spec.rb
98
+ - spec/spec_helper.rb