omniauth-deezer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/Readme.md +120 -0
- data/lib/omniauth-deezer.rb +1 -0
- data/lib/omniauth/deezer.rb +2 -0
- data/lib/omniauth/deezer/version.rb +5 -0
- data/lib/omniauth/strategies/deezer.rb +112 -0
- data/omniauth-deezer.gemspec +27 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Readme.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# OmniAuth Deezer
|
2
|
+
|
3
|
+
Deezer API V2 Strategy for OmniAuth 1.0.
|
4
|
+
|
5
|
+
Supports the OAuth-like Deezer API V2 server-side flow. Read the Deezer docs for more details: http://www.deezer.com/en/developers/simpleapi/oauth
|
6
|
+
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
Add to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-deezer'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then `bundle install`.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
`OmniAuth::Strategies::Deezer` is a plugin to OmniAuth 1.0. See Omniauth docs for more information : https://github.com/intridea/omniauth.
|
20
|
+
|
21
|
+
Add to your `Gemfile`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'omniauth-facebook'
|
25
|
+
```
|
26
|
+
|
27
|
+
Then run `bundle install`.
|
28
|
+
|
29
|
+
Create an app on Deezer website and save your app id and app secret.
|
30
|
+
|
31
|
+
In your Rack application, for instance in your Rails application, add the following lines in `config/initializers/omniauth.rb`and use your app id and secret.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
35
|
+
provider :deezer, ENV['DEEZER_APP_ID'], ENV['DEEZER_APP_SECRET'], :perms => 'basic_access,email'
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Then change your routes in your application `config/routes.rb`
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
OmniauthTest::Application.routes.draw do
|
43
|
+
match 'auth/deezer/callback' => 'sessions#create'
|
44
|
+
match 'auth/failure' => 'errors#login_failed'
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Then start your app and point your browser to /auth/deezer
|
49
|
+
|
50
|
+
## Configuring
|
51
|
+
|
52
|
+
You can only configure :
|
53
|
+
|
54
|
+
* `perms`: A comma-separated list of permissions you want to request from the user. See the Deezer docs for a full list of available permissions: http://www.deezer.com/en/developers/simpleapi/oauth.
|
55
|
+
Default: `basic_access`
|
56
|
+
|
57
|
+
## Authentication Hash
|
58
|
+
|
59
|
+
Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
---
|
63
|
+
provider: deezer
|
64
|
+
uid: '999999'
|
65
|
+
info:
|
66
|
+
name: John Smith
|
67
|
+
nickname: jsmith
|
68
|
+
last_name: John
|
69
|
+
first_name: Smith
|
70
|
+
location: FR
|
71
|
+
image: http://api.deezer.com/2.0/user/999999/image
|
72
|
+
urls:
|
73
|
+
Deezer: http://www.deezer.com/profile/999999
|
74
|
+
email: john.smith@example.com
|
75
|
+
credentials:
|
76
|
+
token: 0xAOhmGc74f33d7f3e24567wSPwGIvI4f33d7f3e219am8n1xho
|
77
|
+
expires: 'true'
|
78
|
+
expires_at: 3600
|
79
|
+
extra:
|
80
|
+
raw_info:
|
81
|
+
id: '304418'
|
82
|
+
name: jsmith
|
83
|
+
lastname: Smith
|
84
|
+
firstname: John
|
85
|
+
email: john.smith@example.com
|
86
|
+
birthday: '1975-01-01'
|
87
|
+
inscription_date: '2007-02-01'
|
88
|
+
gender: M
|
89
|
+
link: http://www.deezer.com/profile/999999
|
90
|
+
picture: http://api.deezer.com/2.0/user/999999/image
|
91
|
+
country: FR
|
92
|
+
type: user
|
93
|
+
```
|
94
|
+
|
95
|
+
The precise information available may depend on the permissions which you request.
|
96
|
+
|
97
|
+
## Supported Rubies
|
98
|
+
|
99
|
+
Actively tested with the following Ruby versions:
|
100
|
+
|
101
|
+
- MRI 1.9.2
|
102
|
+
|
103
|
+
## Tests
|
104
|
+
|
105
|
+
This first version does not have any automated test. I'm really sorry.
|
106
|
+
But you're really welcome to help me add some !
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
This is my first GEM, so don't hesitate to raise bugs, fork, and submit bug fixes and automated tests!
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
Copyright 2012 by Geoffroy Montel
|
115
|
+
|
116
|
+
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:
|
117
|
+
|
118
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
119
|
+
|
120
|
+
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 @@
|
|
1
|
+
require 'omniauth/deezer'
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'omniauth'
|
3
|
+
require 'faraday'
|
4
|
+
require 'cgi'
|
5
|
+
require 'multi_json'
|
6
|
+
|
7
|
+
module OmniAuth
|
8
|
+
module Strategies
|
9
|
+
class Deezer
|
10
|
+
include OmniAuth::Strategy
|
11
|
+
|
12
|
+
DEFAULT_PERMS = "basic_access"
|
13
|
+
|
14
|
+
option :name, "deezer"
|
15
|
+
|
16
|
+
# request phase
|
17
|
+
|
18
|
+
args [:app_id,:app_secret]
|
19
|
+
|
20
|
+
option :client_options, {
|
21
|
+
:authorize_url => 'http://connect.deezer.com/oauth/auth.php',
|
22
|
+
:token_url => 'http://connect.deezer.com/oauth/access_token.php',
|
23
|
+
:me_url => 'http://api.deezer.com/2.0/user/me'
|
24
|
+
}
|
25
|
+
|
26
|
+
option :authorize_options, [:perms]
|
27
|
+
|
28
|
+
def request_phase
|
29
|
+
options.perms ||= DEFAULT_PERMS
|
30
|
+
redirecting_to = options.client_options.authorize_url+'?app_id='+options.app_id+'&redirect_uri='+CGI::escape(callback_url)+'&perms='+options.perms
|
31
|
+
redirect redirecting_to
|
32
|
+
end
|
33
|
+
|
34
|
+
# callback phase
|
35
|
+
|
36
|
+
def callback_phase
|
37
|
+
begin
|
38
|
+
if request.params['error_reason'] then
|
39
|
+
raise CredentialsError, request.params['error_reason']
|
40
|
+
end
|
41
|
+
|
42
|
+
# get token from Deezer
|
43
|
+
token_url = options.client_options.token_url+'?app_id='+options.app_id+'&secret='+options.app_secret+'&code='+request.params['code']
|
44
|
+
response = Faraday.get token_url
|
45
|
+
response_hash = CGI::parse(response.body.chomp)
|
46
|
+
@access_token = response_hash['access_token'][0]
|
47
|
+
@token_expires_at = response_hash['expires'][0].to_i
|
48
|
+
me_path = options.client_options.me_url+'?access_token='+@access_token
|
49
|
+
# get info from current user
|
50
|
+
response = Faraday.get me_path
|
51
|
+
@raw_info = MultiJson.decode(response.body.chomp)
|
52
|
+
|
53
|
+
super
|
54
|
+
|
55
|
+
rescue ::MultiJson::DecodeError => e
|
56
|
+
fail!(:invalid_response, e)
|
57
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
58
|
+
fail!(:timeout, e)
|
59
|
+
rescue ::SocketError => e
|
60
|
+
fail!(:failed_to_connect, e)
|
61
|
+
rescue TypeError => e
|
62
|
+
fail!(:invalid_response, e)
|
63
|
+
rescue CredentialsError => e
|
64
|
+
fail!(:invalid_credentials, e)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
uid { @raw_info['id'] }
|
69
|
+
|
70
|
+
info do
|
71
|
+
h =
|
72
|
+
{
|
73
|
+
:name => @raw_info['firstname']+' '+@raw_info['lastname'],
|
74
|
+
:nickname => @raw_info['name'],
|
75
|
+
:last_name => @raw_info['firstname'],
|
76
|
+
:first_name => @raw_info['lastname'],
|
77
|
+
:location => @raw_info['country'],
|
78
|
+
:image => @raw_info['picture'],
|
79
|
+
:urls => { :Deezer => @raw_info['link'] }
|
80
|
+
}
|
81
|
+
# add email if returned by deezer
|
82
|
+
if @raw_info['email'] then h[:email] = @raw_info['email'] end
|
83
|
+
h
|
84
|
+
end
|
85
|
+
|
86
|
+
credentials do
|
87
|
+
{
|
88
|
+
:token => @access_token,
|
89
|
+
:expires => @token_expires_at > 0 ? 'true' : 'false',
|
90
|
+
:expires_at => @token_expires_at
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
extra do
|
95
|
+
{
|
96
|
+
:raw_info => @raw_info
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
protected
|
101
|
+
|
102
|
+
class CredentialsError < StandardError
|
103
|
+
attr_accessor :error
|
104
|
+
|
105
|
+
def initialize(error)
|
106
|
+
self.error = error
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth/deezer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-deezer"
|
7
|
+
s.version = Omniauth::Deezer::VERSION
|
8
|
+
s.authors = ["Geoffroy Montel"]
|
9
|
+
s.email = ["coder@minizza.com"]
|
10
|
+
s.homepage = "https://github.com/geoffroymontel/omniauth-deezer"
|
11
|
+
s.summary = %q{Deezer strategy for Omniauth 1.0}
|
12
|
+
s.description = %q{Deezer strategy for Omniauth 1.0}
|
13
|
+
|
14
|
+
s.rubyforge_project = "omniauth-deezer"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_runtime_dependency 'omniauth', '~> 1.0.0'
|
23
|
+
s.add_runtime_dependency 'faraday'
|
24
|
+
|
25
|
+
# s.add_development_dependency "rspec"
|
26
|
+
# s.add_runtime_dependency "rest-client"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-deezer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Geoffroy Montel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-09 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: &71363960 !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: *71363960
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: faraday
|
27
|
+
requirement: &71363690 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *71363690
|
36
|
+
description: Deezer strategy for Omniauth 1.0
|
37
|
+
email:
|
38
|
+
- coder@minizza.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Rakefile
|
46
|
+
- Readme.md
|
47
|
+
- lib/omniauth-deezer.rb
|
48
|
+
- lib/omniauth/deezer.rb
|
49
|
+
- lib/omniauth/deezer/version.rb
|
50
|
+
- lib/omniauth/strategies/deezer.rb
|
51
|
+
- omniauth-deezer.gemspec
|
52
|
+
homepage: https://github.com/geoffroymontel/omniauth-deezer
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: omniauth-deezer
|
72
|
+
rubygems_version: 1.8.15
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Deezer strategy for Omniauth 1.0
|
76
|
+
test_files: []
|