omniauth-everyplay 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ .idea
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
7
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'omniauth-oauth2', :git => 'git://github.com/intridea/omniauth-oauth2.git'
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # OmniAuth Everyplay
2
+
3
+ This gem contains the Everyplay strategy for OmniAuth 1.0.
4
+
5
+ ## Installing
6
+
7
+ Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'omniauth-everyplay', '~> 1.0.0'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ ## Basic Usage
16
+
17
+ use OmniAuth::Builder do
18
+ provider "everyplay", ENV['EVERYPLAY_CLIENT_ID'], ENV['EVERYPLAY_SECRET']
19
+ end
20
+
21
+ ## Supported Flows
22
+
23
+ Supports the Server-side Flow as described in the the [Everyplay docs](http://developers.everyplay.com/).
24
+
25
+ ## Auth Hash
26
+
27
+ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
28
+ ```ruby
29
+ {
30
+ "provider" => "everyplay",
31
+ "uid" => 1,
32
+ "info" => {
33
+ "username" => "Nomon",
34
+ "permalink" => "nomon",
35
+ "image" => "https://the.avatar.url"
36
+ },
37
+ "credentials" => {
38
+ "token" => "123-321",
39
+ "expires" => false
40
+ },
41
+ "extra" => {
42
+ "raw_info" => {
43
+ "id": 1,
44
+ "hidden": false,
45
+ "avatar_url_small": "https://www.everyplay.com/assets/img/icon-default-avatar-small.png",
46
+ "avatar_url": "https://www.yammer.com/mugshot/75x75/2270139",
47
+ "cover_url": "https://www.everyplay.com/assets/img/icon-default-cover.jpeg",
48
+ "username": "Nomon",
49
+ "permalink": "nomon",
50
+ "created_at": "2013-01-06T09:31:01.037Z",
51
+ "games_count": 4,
52
+ "online": false,
53
+ "video_count": 116,
54
+ "followings_count": 32,
55
+ "followers_count": 118,
56
+ "permalink_url": "https://m.everyplay.com/nomon", \
57
+ "uri": "https://api.everyplay.com/users/1", \
58
+ "video_likes_count": 1,
59
+ "kind": "user",
60
+ "user_followed": false
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ ## Thanks & Credits
67
+
68
+ [omniauth](https://github.com/intridea/omniauth)
69
+
70
+ [omniauth-soundcloud](https://github.com/soundcloud/omniauth-soundcloud)
71
+
72
+ [Matti Savolainen](https://github.com/Nomon)
73
+
74
+ ## License
75
+
76
+ Original work Copyright (c) 2011 by Lee Martin and SoundCloud
77
+ Modified work Copyright (c) 2013 by Matti Savolainen and Applifier
78
+
79
+ 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:
80
+
81
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
82
+
83
+ 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,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/example/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'json'
4
+ gem 'sinatra'
5
+ gem 'omniauth-everyplay', :path => '../'
data/example/config.ru ADDED
@@ -0,0 +1,28 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'json'
4
+ require 'omniauth-everyplay'
5
+
6
+ class App < Sinatra::Base
7
+ get '/' do
8
+ redirect '/auth/everyplay'
9
+ end
10
+
11
+ get '/auth/:provider/callback' do
12
+ content_type 'application/json'
13
+ MultiJson.encode(request.env['omniauth.auth'])
14
+ end
15
+
16
+ get '/auth/failure' do
17
+ content_type 'application/json'
18
+ MultiJson.encode(request.env['omniauth.auth'])
19
+ end
20
+ end
21
+
22
+ use Rack::Session::Cookie
23
+
24
+ use OmniAuth::Builder do
25
+ provider :everyplay, ENV['EVERYPLAY_CLIENT_ID'], ENV['EVERYPLAY_SECRET'], :scope => 'basic'
26
+ end
27
+
28
+ run App.new
@@ -0,0 +1 @@
1
+ require 'omniauth/everyplay'
@@ -0,0 +1,2 @@
1
+ require 'omniauth/everyplay/version'
2
+ require 'omniauth/strategies/everyplay'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Everyplay
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,78 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Everyplay < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = 'basic'
7
+
8
+ option :name, "everyplay"
9
+
10
+ option :client_options, {
11
+ :site => 'https://api.everyplay.com',
12
+ :authorize_url => 'https://everyplay.com/connect',
13
+ :token_url => '/oauth2/access_token'
14
+ }
15
+
16
+ option :access_token_options, {
17
+ :header_format => 'Bearer %s',
18
+ :param_name => 'access_token'
19
+ }
20
+
21
+
22
+ uid { raw_info['id'] }
23
+
24
+ info do
25
+ prune!({
26
+ 'nickname' => raw_info['username'],
27
+ 'name' => raw_info['username'],
28
+ 'image' => raw_info['avatar_url']
29
+ })
30
+ end
31
+
32
+ credentials do
33
+ prune!({
34
+ 'expires' => access_token.expires?,
35
+ 'expires_at' => access_token.expires_at
36
+ })
37
+ end
38
+
39
+ extra do
40
+ prune!({
41
+ 'raw_info' => raw_info
42
+ })
43
+ end
44
+
45
+ def raw_info
46
+ @raw_info ||= access_token.get('/me').parsed
47
+ end
48
+
49
+ def build_access_token
50
+ super.tap do |token|
51
+ token.options.merge!(access_token_options)
52
+ end
53
+ end
54
+
55
+ def access_token_options
56
+ options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
57
+ end
58
+
59
+ def authorize_params
60
+ super.tap do |params|
61
+ %w[display state scope].each { |v| params[v.to_sym] = request.params[v] if request.params[v] }
62
+ params[:scope] ||= DEFAULT_SCOPE
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def prune!(hash)
69
+ hash.delete_if do |_, value|
70
+ prune!(value) if value.is_a?(Hash)
71
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ OmniAuth.config.add_camelization 'everyplay', 'Everyplay'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/everyplay/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-everyplay'
7
+ s.version = OmniAuth::Everyplay::VERSION
8
+ s.authors = ['Matti Savolainen']
9
+ s.email = ['matti@applifier.com']
10
+ s.summary = 'Everyplay strategy for OmniAuth'
11
+ s.homepage = 'https://github.com/Everyplay/omniauth-everyplay'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1.0'
19
+
20
+ s.add_development_dependency 'rspec', '~> 2.7'
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'webmock'
23
+ s.add_development_dependency 'rack-test'
24
+
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "OmniAuth::Strategies::Everyplay" do
4
+ subject do
5
+ OmniAuth::Strategies::Everyplay.new(nil, @options || {})
6
+ end
7
+
8
+ context 'client options' do
9
+ it 'has correct Everyplay site' do
10
+ subject.options.client_options.site.should eq('https://api.everyplay.com')
11
+ end
12
+
13
+
14
+ it 'has correct access token path' do
15
+ subject.options.client_options.token_url.should eq('/oauth2/access_token')
16
+ end
17
+
18
+ it 'has correct authorize url' do
19
+ subject.options.client_options.authorize_url.should eq('https://everyplay.com/connect')
20
+ end
21
+ end
22
+
23
+ context '#uid' do
24
+ before :each do
25
+ subject.stub(:raw_info) { { 'id' => '1' } }
26
+ end
27
+
28
+ it 'returns the id from raw_info' do
29
+ subject.uid.should eq('1')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'rack/test'
6
+ require 'webmock/rspec'
7
+ require 'omniauth'
8
+ require 'omniauth-everyplay'
9
+
10
+ RSpec.configure do |config|
11
+ config.include WebMock::API
12
+ config.include Rack::Test::Methods
13
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
14
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-everyplay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Matti Savolainen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-06 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth-oauth2
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 1
31
+ - 1
32
+ - 0
33
+ version: 1.1.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 13
45
+ segments:
46
+ - 2
47
+ - 7
48
+ version: "2.7"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rake
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: webmock
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rack-test
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id005
93
+ description:
94
+ email:
95
+ - matti@applifier.com
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - README.md
106
+ - Rakefile
107
+ - example/Gemfile
108
+ - example/config.ru
109
+ - lib/omniauth-everyplay.rb
110
+ - lib/omniauth/everyplay.rb
111
+ - lib/omniauth/everyplay/version.rb
112
+ - lib/omniauth/strategies/everyplay.rb
113
+ - omniauth-everyplay.gemspec
114
+ - spec/omniauth/strategies/everyplay_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/Everyplay/omniauth-everyplay
117
+ licenses: []
118
+
119
+ post_install_message:
120
+ rdoc_options: []
121
+
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ requirements: []
143
+
144
+ rubyforge_project:
145
+ rubygems_version: 1.8.24
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Everyplay strategy for OmniAuth
149
+ test_files:
150
+ - spec/omniauth/strategies/everyplay_spec.rb
151
+ - spec/spec_helper.rb