omniauth-viddy 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: cad3275faeb427ec2bfbd9a18136eee905aa72b5
4
+ data.tar.gz: 8bec4fd72dc6738ab41dd7a28b835ad61f893598
5
+ SHA512:
6
+ metadata.gz: d851c4e9c40a46350db1271581e69630713ee92fb8e6442b6747fa395e3a4da094e0c5dff4118356feff569b1509279fd57358d07c68099320c18b1e427034f1
7
+ data.tar.gz: 025147535aa94efe6b9dc696d4b43044cff728cad43023d107671772bf895f7c0be997cd0eafd35c737ec52ef62d4e126d3ba5f0431557f157e2af8a8dcf48b2
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ .DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+ # RVM
52
+ .rvmrc
53
+
54
+ Gemfile.lock
55
+
56
+ gems
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Sean Stavropoulos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # OmniAuth Viddy Strategy
2
+
3
+ Strategy to authenticate with Viddy via OAuth2 in OmniAuth.
4
+
5
+ ## Installation
6
+
7
+ `omniauth-viddy` is hosted through [RubyGems](http://rubygems.org/gems/omniauth-viddy). Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem "omniauth-viddy"
11
+ ```
12
+ Then `bundle install`.
13
+
14
+ ## Usage
15
+
16
+ Here's an example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
17
+
18
+ ```ruby
19
+ Rails.application.config.middleware.use OmniAuth::Builder do
20
+ provider :viddy, ENV["VIDDY_KEY"]
21
+ end
22
+ ```
23
+
24
+ You can now access the OmniAuth Viddy OAuth2 URL: `/auth/viddy`
25
+
26
+ ### Devise
27
+
28
+ For devise, you should also make sure you have an OmniAuth callback controller setup
29
+
30
+ ```ruby
31
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
32
+ def viddy
33
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
34
+ @user = User.find_for_viddy_oauth(request.env["omniauth.auth"], current_user)
35
+
36
+ if @user.persisted?
37
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "viddy"
38
+ sign_in_and_redirect @user, :event => :authentication
39
+ else
40
+ session["devise.viddy_data"] = request.env["omniauth.auth"]
41
+ redirect_to new_user_registration_url
42
+ end
43
+ end
44
+ end
45
+ ```
46
+
47
+ and bind to or create the user
48
+
49
+ ```ruby
50
+ def self.find_for_viddy_oauth(access_token, signed_in_resource=nil)
51
+ data = access_token.info
52
+ user = User.where(:email => data["email"]).first
53
+
54
+ unless user
55
+ user = User.create(name: data["name"],
56
+ email: data["email"],
57
+ password: Devise.friendly_token[0,20]
58
+ )
59
+ end
60
+ user
61
+ end
62
+ ```
63
+ ## Configuration
64
+
65
+ You can configure several options, which you pass in to the `provider` method via a hash:
66
+
67
+ ## Auth Hash
68
+
69
+ Here's an example of an authentication hash available in the callback by accessing `request.env["omniauth.auth"]`:
70
+
71
+ ```ruby
72
+ {
73
+ "provider"=>"viddy",
74
+ "uid"=>"1d3344aa-4a2f-430b-b48d-4dc4d3dcec2f",
75
+ "info"=>{
76
+ "full_name"=>"seanstavro",
77
+ "username"=>"seanstavro",
78
+ "profile"=>"http://www.viddy.com/seanstavro",
79
+ "thumbnail"=>"http://cdn.viddy.com/images/users/thumb/1d3344aa-4a2f-430b-b48d-4dc4d3dcec2f_150x150.jpg?t=0",
80
+ "profile_picture"=>"http://cdn.viddy.com/images/users/1d3344aa-4a2f-430b-b48d-4dc4d3dcec2f.jpg?t=0",
81
+ "email"=>"sean@fullscreen.net",
82
+ "name"=>"sean@fullscreen.net"
83
+ },
84
+ "credentials"=>{
85
+ "access_token"=>"..."
86
+ },
87
+ "extra"=>{
88
+ "user_info"=>{
89
+ "username"=>"seanstavro",
90
+ "profile"=>"http://www.viddy.com/seanstavro",
91
+ "relationship_status"=>0,
92
+ "following_count"=>41,
93
+ "videos_count"=>0,
94
+ "timestamp"=>13886861400000000,
95
+ "thumbnail"=>{
96
+ "url"=>"http://cdn.viddy.com/images/users/thumb/1d3344aa-4a2f-430b-b48d-4dc4d3dcec2f_150x150.jpg?t=0"
97
+ },
98
+ "email"=>"sean@fullscreen.net",
99
+ "followers_count"=>5,
100
+ "profile_picture"=>{
101
+ "url"=>"http://cdn.viddy.com/images/users/1d3344aa-4a2f-430b-b48d-4dc4d3dcec2f.jpg?t=0"
102
+ },
103
+ "full_name"=>"seanstavro",
104
+ "facebook_id"=>6411701,
105
+ "unix_timestamp"=>1388686140,
106
+ "id"=>"1d3344aa-4a2f-430b-b48d-4dc4d3dcec2f"
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ ## License
113
+
114
+ Copyright (c) 2014 Sean Stavropoulos
115
+
116
+ Permission is hereby granted, free of charge, to any person obtaining
117
+ a copy of this software and associated documentation files (the
118
+ "Software"), to deal in the Software without restriction, including
119
+ without limitation the rights to use, copy, modify, merge, publish,
120
+ distribute, sublicense, and/or sell copies of the Software, and to
121
+ permit persons to whom the Software is furnished to do so, subject to
122
+ the following conditions:
123
+
124
+ The above copyright notice and this permission notice shall be
125
+ included in all copies or substantial portions of the Software.
126
+
127
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
128
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
129
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
130
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
131
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
132
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
133
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
134
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,42 @@
1
+ # Sample app for Viddy OAuth2 Strategy
2
+ # Make sure to setup the ENV variables VIDDY_KEY
3
+ # Run with "bundle exec rackup"
4
+
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ require 'sinatra'
8
+ require 'omniauth'
9
+ require '../lib/omniauth-viddy'
10
+
11
+ # Do not use for production code.
12
+ # This is only to make setup easier when running through the sample.
13
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
14
+
15
+ class App < Sinatra::Base
16
+ get '/' do
17
+ <<-HTML
18
+ <ul>
19
+ <li><a href='/auth/viddy'>Sign in with Viddy</a></li>
20
+ </ul>
21
+ HTML
22
+ end
23
+
24
+ get '/auth/:provider/callback' do
25
+ content_type 'text/plain'
26
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
27
+ end
28
+
29
+ get '/auth/failure' do
30
+ content_type 'text/plain'
31
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
32
+ end
33
+ end
34
+
35
+ use Rack::Session::Cookie, :secret => ENV['RACK_COOKIE_SECRET']
36
+
37
+ use OmniAuth::Builder do
38
+ # Regular usage
39
+ provider :viddy, ENV['VIDDY_KEY']
40
+ end
41
+
42
+ run App.new
@@ -0,0 +1,3 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ provider :viddy, ENV['VIDDY_KEY']
3
+ end
@@ -0,0 +1,104 @@
1
+ require 'oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Viddy
6
+ include OmniAuth::Strategy
7
+
8
+ attr_accessor :access_token
9
+
10
+ args [:apikey]
11
+
12
+ option :apikey
13
+
14
+ option :name, 'viddy'
15
+
16
+ option :client_options, {
17
+ site: 'https://api.viddy.com',
18
+ authorize_url: 'https://viddy.com/oauth/authenticate',
19
+ }
20
+
21
+ def client
22
+ ::OAuth2::Client.new(options.apikey, nil, deep_symbolize(options.client_options).merge(connection_opts: {params:{apikey: options.apikey}}))
23
+ end
24
+
25
+ credentials do
26
+ {'access_token' => access_token.token}
27
+ end
28
+
29
+ uid { raw_info['id'] }
30
+
31
+ info do
32
+ {
33
+ full_name: raw_info['full_name'],
34
+ username: raw_info['username'],
35
+ profile: raw_info['profile'],
36
+ thumbnail: raw_info['thumbnail']['url'],
37
+ profile_picture: raw_info['profile_picture']['url'],
38
+ email: raw_info['email']
39
+ }
40
+ end
41
+
42
+ extra do
43
+ {
44
+ user_info: raw_info
45
+ }
46
+ end
47
+
48
+ def raw_info
49
+ @raw_info ||= @access_token.get("/v1/users/me").parsed['users'][0]
50
+ end
51
+
52
+ protected
53
+
54
+ def deep_symbolize(options)
55
+ hash = {}
56
+ options.each do |key, value|
57
+ hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
58
+ end
59
+ hash
60
+ end
61
+
62
+ def request_phase
63
+ redirect client.auth_code.authorize_url
64
+ end
65
+
66
+ def callback_phase
67
+ error = request.params['error_reason'] || request.params['error']
68
+ if error
69
+ fail!(error, CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']))
70
+ else
71
+ self.access_token = ::OAuth2::AccessToken.new(client, request.params['access_token'], :mode => :query)
72
+ super
73
+ end
74
+ rescue ::OAuth2::Error, CallbackError => e
75
+ fail!(:invalid_credentials, e)
76
+ rescue ::MultiJson::DecodeError => e
77
+ fail!(:invalid_response, e)
78
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT, Faraday::Error::TimeoutError => e
79
+ fail!(:timeout, e)
80
+ rescue ::SocketError, Faraday::Error::ConnectionFailed => e
81
+ fail!(:failed_to_connect, e)
82
+ end
83
+
84
+ # An error that is indicated in the OAuth 2.0 callback.
85
+ # This could be a `redirect_uri_mismatch` or other
86
+ class CallbackError < StandardError
87
+ attr_accessor :error, :error_reason, :error_uri
88
+
89
+ def initialize(error, error_reason = nil, error_uri = nil)
90
+ self.error = error
91
+ self.error_reason = error_reason
92
+ self.error_uri = error_uri
93
+ end
94
+
95
+ def message
96
+ [error, error_reason, error_uri].compact.join(' | ')
97
+ end
98
+ end
99
+
100
+ end
101
+ end
102
+ end
103
+
104
+ OmniAuth.config.add_camelization 'viddy', 'Viddy'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Viddy
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'omniauth/viddy/version'
2
+ require_relative 'omniauth/strategies/viddy'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth/viddy/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sean Stavropoulos"]
6
+ gem.email = ["sean@fullscreen.net"]
7
+ gem.description = %q{Viddy OAuth2 strategy}
8
+ gem.summary = %q{Viddy OAuth2 strategy}
9
+ gem.homepage = "https://github.com/Fullscreen/omniauth-viddy"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "omniauth-viddy"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::Viddy::VERSION
17
+
18
+ gem.add_runtime_dependency 'oauth2'
19
+
20
+ gem.add_development_dependency 'rspec', '~> 2.6.0'
21
+ gem.add_development_dependency 'rake'
22
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-viddy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Stavropoulos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.6.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.6.0
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: Viddy OAuth2 strategy
56
+ email:
57
+ - sean@fullscreen.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - examples/config.ru
69
+ - examples/omni_auth.rb
70
+ - lib/omniauth-viddy.rb
71
+ - lib/omniauth/strategies/viddy.rb
72
+ - lib/omniauth/viddy/version.rb
73
+ - omniauth-viddy.gemspec
74
+ homepage: https://github.com/Fullscreen/omniauth-viddy
75
+ licenses: []
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.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Viddy OAuth2 strategy
97
+ test_files: []
98
+ has_rdoc: