omniauth-soundcloud 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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'
@@ -0,0 +1,33 @@
1
+ # OmniAuth SoundCloud
2
+
3
+ This gem contains the SoundCloud strategy for OmniAuth 1.0.
4
+
5
+ ## Installing
6
+
7
+ Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'omniauth-soundcloud', '~> 1.0.0'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ ## Basic Usage
16
+
17
+ use OmniAuth::Builder do
18
+ provider "soundcloud", ENV['SOUNDCLOUD_CLIENT_ID'], ENV['SOUNDCLOUD_SECRET']
19
+ end
20
+
21
+ ## Supported Flows
22
+
23
+ Supports the Server-side Flow as described in the the [SoundCloud docs](http://developers.soundcloud.com/docs/api/authentication#authorization-code-flow).
24
+
25
+ ## License
26
+
27
+ Copyright (c) 2011 by Lee Martin and SoundCloud
28
+
29
+ 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:
30
+
31
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32
+
33
+ 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.
@@ -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
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'omniauth-soundcloud', :path => '../'
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-soundcloud'
4
+
5
+ class App < Sinatra::Base
6
+ get '/' do
7
+ redirect '/auth/soundcloud'
8
+ end
9
+
10
+ get '/auth/:provider/callback' do
11
+ content_type 'application/json'
12
+ MultiJson.encode(request.env)
13
+ end
14
+
15
+ get '/auth/failure' do
16
+ content_type 'application/json'
17
+ MultiJson.encode(request.env)
18
+ end
19
+ end
20
+
21
+ use Rack::Session::Cookie
22
+
23
+ use OmniAuth::Builder do
24
+ provider :soundcloud, ENV['APP_ID'], ENV['APP_SECRET'], :scope => 'non-expiring'
25
+ end
26
+
27
+ run App.new
@@ -0,0 +1 @@
1
+ require 'omniauth/soundcloud'
@@ -0,0 +1,2 @@
1
+ require 'omniauth/soundcloud/version'
2
+ require 'omniauth/strategies/soundcloud'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module SoundCloud
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,82 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class SoundCloud < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = 'non-expiring'
7
+
8
+ option :name, "soundcloud"
9
+
10
+ option :client_options, {
11
+ :site => 'https://api.soundcloud.com',
12
+ :authorize_url => '/connect',
13
+ :token_url => '/oauth2/token'
14
+ }
15
+
16
+ option :access_token_options, {
17
+ :header_format => 'OAuth %s',
18
+ :param_name => 'access_token'
19
+ }
20
+
21
+ uid { raw_info['id'] }
22
+
23
+ info do
24
+ prune!({
25
+ 'nickname' => raw_info['username'],
26
+ 'name' => raw_info['full_name'],
27
+ 'image' => raw_info['avatar_url'],
28
+ 'description' => raw_info['description'],
29
+ 'urls' => {
30
+ 'Website' => raw_info['website']
31
+ },
32
+ 'location' => raw_info['city']
33
+ })
34
+ end
35
+
36
+ credentials do
37
+ prune!({
38
+ 'expires' => access_token.expires?,
39
+ 'expires_at' => access_token.expires_at
40
+ })
41
+ end
42
+
43
+ extra do
44
+ prune!({
45
+ 'raw_info' => raw_info
46
+ })
47
+ end
48
+
49
+ def raw_info
50
+ @raw_info ||= access_token.get('/me.json').parsed
51
+ end
52
+
53
+ def build_access_token
54
+ super.tap do |token|
55
+ token.options.merge!(access_token_options)
56
+ end
57
+ end
58
+
59
+ def access_token_options
60
+ options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
61
+ end
62
+
63
+ def authorize_params
64
+ super.tap do |params|
65
+ # params.merge!(:display => request.params['display']) if request.params['display']
66
+ params[:scope] ||= DEFAULT_SCOPE
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def prune!(hash)
73
+ hash.delete_if do |_, value|
74
+ prune!(value) if value.is_a?(Hash)
75
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ OmniAuth.config.add_camelization 'soundcloud', 'SoundCloud'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/soundcloud/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-soundcloud'
7
+ s.version = OmniAuth::SoundCloud::VERSION
8
+ s.authors = ['Lee Martin']
9
+ s.email = ['lee@soundcloud.com']
10
+ s.summary = 'SoundCloud strategy for OmniAuth'
11
+ s.homepage = 'https://github.com/soundcloud/omniauth-soundcloud'
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.0.0'
19
+
20
+ s.add_development_dependency 'rspec', '~> 2.7.0'
21
+ s.add_development_dependency 'rake'
22
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-soundcloud'
3
+
4
+ describe OmniAuth::Strategies::SoundCloud do
5
+ subject do
6
+ OmniAuth::Strategies::SoundCloud.new(nil, @options || {})
7
+ end
8
+
9
+ it_should_behave_like 'an oauth2 strategy'
10
+
11
+ describe '#client' do
12
+ it 'should have the correct SoundCloud site' do
13
+ subject.client.site.should eq("https://api.soundcloud.com")
14
+ end
15
+
16
+ it 'should have the correct authorization url' do
17
+ subject.client.options[:authorize_url].should eq("/connect")
18
+ end
19
+
20
+ it 'should have the correct token url' do
21
+ subject.client.options[:token_url].should eq('/oauth2/token')
22
+ end
23
+ end
24
+
25
+ describe '#callback_path' do
26
+ it 'should have the correct callback path' do
27
+ subject.callback_path.should eq('/auth/soundcloud/callback')
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ describe '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.authorize_params['foo'].should eq('bar')
14
+ subject.authorize_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('bar')
20
+ subject.authorize_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any authorize params passed in the :authorize_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :authorize_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-soundcloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lee Martin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth2
16
+ requirement: &70219109416760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70219109416760
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70219109416200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70219109416200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70219109415560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70219109415560
47
+ description:
48
+ email:
49
+ - lee@soundcloud.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - Gemfile
55
+ - README.md
56
+ - Rakefile
57
+ - example/Gemfile
58
+ - example/config.ru
59
+ - lib/omniauth-soundcloud.rb
60
+ - lib/omniauth/soundcloud.rb
61
+ - lib/omniauth/soundcloud/version.rb
62
+ - lib/omniauth/strategies/soundcloud.rb
63
+ - omniauth-soundcloud.gemspec
64
+ - spec/omniauth/strategies/soundcloud_spec.rb
65
+ - spec/spec_helper.rb
66
+ - spec/support/shared_examples.rb
67
+ homepage: https://github.com/soundcloud/omniauth-soundcloud
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ segments:
80
+ - 0
81
+ hash: 1733435778679222157
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: 1733435778679222157
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.11
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: SoundCloud strategy for OmniAuth
97
+ test_files:
98
+ - spec/omniauth/strategies/soundcloud_spec.rb
99
+ - spec/spec_helper.rb
100
+ - spec/support/shared_examples.rb