omniauth-stackexchange 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'minitest', '~> 3.0'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Vasiliy Ermolovich
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # OmniAuth StackExchange [![TravisCI](https://secure.travis-ci.org/nashby/omniauth-stackexchange.png?branch=master)](http://travis-ci.org/nashby/omniauth-stackexchange)
2
+
3
+ This gem contains the StackExchange strategy for OmniAuth.
4
+
5
+ StackExchange uses the OAuth2 flow, you can read about it here: https://api.stackexchange.com/docs/authentication
6
+
7
+ ## How To Use It
8
+
9
+ So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-stackexchange'
13
+ ```
14
+
15
+ You can pull them in directly from github e.g.:
16
+
17
+ ```ruby
18
+ gem 'omniauth-stackexchange', :git => 'https://github.com/nashby/omniauth-stackexchange.git'
19
+ ```
20
+
21
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
22
+
23
+ ```ruby
24
+ Rails.application.config.middleware.use OmniAuth::Builder do
25
+ provider :stackexchange, "client_id", "client_secret", public_key: "key"
26
+ end
27
+ ```
28
+
29
+ You will obviously have to put in your client_id, client_secret and public_key, which you get when you register your app with StackExchange (they call them Client Id, Client Secret and Key).
30
+
31
+ Now just follow the README at: https://github.com/intridea/omniauth
32
+
33
+ ## Supported Rubies
34
+
35
+ OmniAuth StackExchange is tested under 1.9.3.
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
44
+
45
+ ## License
46
+
47
+ Copyright (c) 2012 by Vasiliy Ermolovich
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = 'test/*_test.rb'
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ require 'omniauth-stackexchange/version'
2
+ require 'omniauth/strategies/stackexchange'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module StackExchange
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,52 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class StackExchange < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://api.stackexchange.com/2.0',
8
+ :authorize_url => 'https://stackexchange.com/oauth',
9
+ :token_url => 'https://stackexchange.com/oauth/access_token'
10
+ }
11
+
12
+ option :token_params, {
13
+ :parse => :query
14
+ }
15
+
16
+ def request_phase
17
+ super
18
+ end
19
+
20
+ uid { raw_info['user_id'] }
21
+
22
+ info do
23
+ {
24
+ 'nickname' => raw_info['display_name'],
25
+ 'image' => raw_info['profile_image'],
26
+ 'urls' => {
27
+ 'StackOverflow' => raw_info['link']
28
+ },
29
+
30
+ }
31
+ end
32
+
33
+ extra do
34
+ { :raw_info => raw_info }
35
+ end
36
+
37
+ def raw_info
38
+ @raw_info ||= access_token.get('me', :params => params).parsed['items'].first
39
+ end
40
+
41
+ def params
42
+ {
43
+ :site => 'stackoverflow',
44
+ :access_token => access_token.token,
45
+ :key => options.public_key
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ OmniAuth.config.add_camelization 'stackexchange', 'StackExchange'
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-stackexchange/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Vasiliy Ermolovich"]
6
+ gem.email = ["younash@gmail.com"]
7
+ gem.description = %q{StackExchange OAuth strategy for OmniAuth}
8
+ gem.summary = %q{StackExchange OAuth strategy for OmniAuth}
9
+ gem.homepage = "https://github.com/nashby/omniauth-stackexchange"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "omniauth-stackexchange"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Omniauth::StackExchange::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ describe OmniAuth::Strategies::StackExchange do
4
+ let(:stackexchange) do
5
+ OmniAuth::Strategies::StackExchange.new({})
6
+ end
7
+
8
+ it 'has correct site' do
9
+ stackexchange.options.client_options.site.must_equal("https://api.stackexchange.com/2.0")
10
+ end
11
+
12
+ it 'has correct authorize url' do
13
+ stackexchange.options.client_options.authorize_url.must_equal('https://stackexchange.com/oauth')
14
+ end
15
+
16
+ it 'has correct token url' do
17
+ stackexchange.options.client_options.token_url.must_equal('https://stackexchange.com/oauth/access_token')
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+
4
+ require 'omniauth'
5
+ require 'omniauth-stackexchange'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-stackexchange
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vasiliy Ermolovich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &10906540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *10906540
25
+ - !ruby/object:Gem::Dependency
26
+ name: omniauth-oauth2
27
+ requirement: &10904860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *10904860
36
+ description: StackExchange OAuth strategy for OmniAuth
37
+ email:
38
+ - younash@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .travis.yml
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - lib/omniauth-stackexchange.rb
50
+ - lib/omniauth-stackexchange/version.rb
51
+ - lib/omniauth/strategies/stackexchange.rb
52
+ - omniauth-stackexchange.gemspec
53
+ - test/stackexchange_test.rb
54
+ - test/test_helper.rb
55
+ homepage: https://github.com/nashby/omniauth-stackexchange
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: 553314339047017420
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: 553314339047017420
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.10
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: StackExchange OAuth strategy for OmniAuth
85
+ test_files:
86
+ - test/stackexchange_test.rb
87
+ - test/test_helper.rb