oauth_rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3d7dec3b8ddf64e1def670e46e3408493215f8d
4
+ data.tar.gz: d71ef09a9b0d1245f953c1c9795bcfe0542a5669
5
+ SHA512:
6
+ metadata.gz: 63f0e2a21d6f0d1a12ee919abdebefc99748dcc229840c7c6e6b846f4995b3a994f4b3547dd3a7788f567ce1181969e69cad624015e1df66f11b2a91e1da82ef
7
+ data.tar.gz: bfcdf7783ce7004877a0b56037ece54fe792cd362d4f47a487e617773f68735b4675b0430e95cf2c3760074be6e366cc729d6dea302d1f07ff7081a91162b091
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in oauth_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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,72 @@
1
+ # OAuthRails
2
+
3
+ This Gem offers an 'invisible' way for an OAuth Handshake in an Rails application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'oauth_rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install oauth_rails
18
+
19
+ Configure a few constants in config/initializers/oauth_rails.rb
20
+
21
+ OAuthRails.setup({
22
+ oauth_host: 'https://api.SOMETHING.com',
23
+ oauth_consumer_key: 'OAUTH_CONSUMER_KEY',
24
+ oauth_consumer_secret: 'OAUTH_CONSUMER_SECRET',
25
+ proc_authorization_successful: Proc.new do |controller_context, token, secret|
26
+ # Do something special (like saving) with the OAuth-'token' and 'secret' and
27
+ # use the 'controller_context' to complete the controller behavior
28
+ controller_context.redirect_to controller_context.root_url
29
+ end,
30
+ proc_authorization_failed: Proc.new { |controller_context| controller_context.root_url }
31
+ })
32
+
33
+
34
+ ## Usage
35
+
36
+ Redirect the user to the __oauth_handshake_path__ and use the procs to define the behaviors for the success and failure situations. Yes, it is so simple! \o/
37
+
38
+ ## Advanced configuration
39
+
40
+ All default settings can be overwritten with the OAuthRails.setup() method
41
+
42
+ DEFAULT_SETTINGS = {
43
+ oauth_host: nil,
44
+ oauth_request_token_path: '/v1/request_token',
45
+ oauth_authorize_path: '/v1/authorize',
46
+ oauth_access_token_path: '/v1/access_token',
47
+ oauth_consumer_key: nil,
48
+ oauth_consumer_secret: nil,
49
+ oauth_callback_url: 'http://localhost:3000/oauth/authorize',
50
+ oauth_verifier_key: :oauth_verifier,
51
+ proc_initialize_handshake: Proc.new { |controller_context| },
52
+ proc_initialize_authorization_failed: Proc.new { |controller_context| OAuthRails.call(:authorization_failed, controller_context) },
53
+ proc_authorization_successful: Proc.new { |controller_context, token, secret| raise "Run 'OAuthRails.setup()' to set a ':proc_authorization_successful'" },
54
+ proc_authorization_failed: Proc.new { |controller_context| raise "Run 'OAuthRails.setup()' to set a ':proc_authorization_failed'" }
55
+ }
56
+
57
+ The procs can be used to execute custom code. The procs __proc_authorization_successful__ and __proc_authorization_failed__ are mandatory for the core functionality., they will be called when the authorization was successful or not. They should handle the OAuth data and redirections.
58
+
59
+
60
+ ## Example application
61
+
62
+ In progress.
63
+
64
+
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it ( https://github.com/[my-github-username]/oauth_rails/fork )
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,55 @@
1
+ class OauthRails::OauthController < ApplicationController
2
+ def handshake
3
+ OAuthRails.call(:initialize_handshake, self)
4
+
5
+ token = consumer.get_request_token(oauth_callback: OAuthRails.config.oauth_callback_url)
6
+ session[:oauth_rails] = { token: token.token, secret: token.secret }
7
+
8
+ redirect_to token.authorize_url
9
+ end
10
+
11
+ def authorize
12
+ return OAuthRails.call(:initialize_authorization_failed, self) if request_token_hash.nil?
13
+
14
+ if access_token
15
+ OAuthRails.call(:authorization_successful, self, access_token.token, access_token.secret)
16
+ else
17
+ OAuthRails.call(:authorization_failed, self)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def consumer
24
+ @consumer ||= ::OAuth::Consumer.new(
25
+ OAuthRails.config.oauth_consumer_key,
26
+ OAuthRails.config.oauth_consumer_secret,
27
+ {
28
+ :site => OAuthRails.config.oauth_host,
29
+ :request_token_path => OAuthRails.config.oauth_request_token_path,
30
+ :authorize_path => OAuthRails.config.oauth_authorize_path,
31
+ :access_token_path => OAuthRails.config.oauth_access_token_path
32
+ }
33
+ )
34
+ end
35
+
36
+ def request_token_hash
37
+ @request_token_hash ||= session.delete(:oauth_rails)
38
+ end
39
+
40
+ def request_token
41
+ @request_token ||= ::OAuth::RequestToken.new(consumer, request_token_hash['token'], request_token_hash['secret'])
42
+ end
43
+
44
+ def access_token
45
+ return if @token_exchange_failed
46
+
47
+ @access_token ||= begin
48
+ request_token.get_access_token(oauth_verifier: params[OAuthRails.config.oauth_verifier_key])
49
+ rescue => e
50
+ logger.debug "OAuthRails [ERROR]: #{e}"
51
+ @token_exchange_failed = true
52
+ nil
53
+ end
54
+ end
55
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+
2
+ Rails.application.routes.draw do
3
+ get '/oauth/handshake', to: 'oauth_rails/oauth#handshake'
4
+ get '/oauth/authorize', to: 'oauth_rails/oauth#authorize'
5
+ end
@@ -0,0 +1,51 @@
1
+ require "oauth_rails/version"
2
+ require "oauth_rails/engine"
3
+ require "oauth"
4
+
5
+ module OAuthRails
6
+ DEFAULT_SETTINGS = {
7
+ oauth_host: nil,
8
+ oauth_request_token_path: '/v1/request_token',
9
+ oauth_authorize_path: '/v1/authorize',
10
+ oauth_access_token_path: '/v1/access_token',
11
+ oauth_consumer_key: nil,
12
+ oauth_consumer_secret: nil,
13
+ oauth_callback_url: 'http://localhost:3000/oauth/authorize',
14
+ oauth_verifier_key: :oauth_verifier,
15
+ proc_initialize_handshake: Proc.new { |controller_context| },
16
+ proc_initialize_authorization_failed: Proc.new { |controller_context| OAuthRails.call(:authorization_failed, controller_context) },
17
+ proc_authorization_successful: Proc.new { |controller_context, token, secret| raise "Run 'OAuthRails.setup()' to set a ':proc_authorization_successful'" },
18
+ proc_authorization_failed: Proc.new { |controller_context| raise "Run 'OAuthRails.setup()' to set a ':proc_authorization_failed'" }
19
+ }
20
+
21
+ def self.setup(user_settings)
22
+ settings = DEFAULT_SETTINGS.merge(user_settings)
23
+
24
+ validate_settings!(settings)
25
+
26
+ @config = ::OpenStruct.new(settings)
27
+ end
28
+
29
+ def self.config
30
+ @config
31
+ end
32
+
33
+ def config
34
+ return self.config if self.config
35
+
36
+ raise "You have run OAuthRails.setup() to set the configuration!"
37
+ end
38
+
39
+ def self.call(name, controller_context, *args)
40
+ name = ['proc_',name].join
41
+ config.send(name).call(controller_context, *args)
42
+ end
43
+
44
+ private
45
+
46
+ def self.validate_settings!(settings)
47
+ settings.each do |key, value|
48
+ raise "You have to set a value for the key ':#{key}' with 'OAuthRails.setup()'!" unless value
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,4 @@
1
+ module OAuthRails
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module OAuthRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oauth_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oauth_rails"
8
+ spec.version = OAuthRails::VERSION
9
+ spec.authors = ["Martin Brendel"]
10
+ spec.email = ["ependichter@gmail.com"]
11
+ spec.description = %q{OAuth magic for Rails}
12
+ spec.summary = %q{An easy way to make a OAuth Handshake}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "oauth"
24
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Brendel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: OAuth magic for Rails
56
+ email:
57
+ - ependichter@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - app/controllers/oauth_rails/oauth_controller.rb
68
+ - config/routes.rb
69
+ - lib/oauth_rails.rb
70
+ - lib/oauth_rails/engine.rb
71
+ - lib/oauth_rails/version.rb
72
+ - oauth_rails.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: An easy way to make a OAuth Handshake
97
+ test_files: []