omniauth-spotify 0.0.10 → 0.0.11
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 +4 -4
- data/README.md +69 -43
- data/lib/omniauth-spotify.rb +16 -3
- data/lib/omniauth-spotify/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b52e324f0a69229ce9d430055f440b5f86a69a3
|
4
|
+
data.tar.gz: 5c8f140624660c6af633a4e14f4f844e2fdc0170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a4146f276e7678cf06522c51ff7a947abb220afc0c1853c09380c9b05564f014a4a4aa4cadf79c334cf93cfd6965d2848b19d0d176987a51ac2cc069c6a5da8
|
7
|
+
data.tar.gz: 2caa8f99d2a67d023283f3d359bd2ead3ca0e97b2fc6ae3b8c763973b9b26b1eb649a4a01ee1f89c11554da3845ceaeed194619d293f1e1c6b575bc441207f4b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Spotify OmniAuth Strategy
|
2
2
|
|
3
|
-
This gem provides a simple way to authenticate to Spotify Web API using OmniAuth with OAuth2.
|
3
|
+
This gem provides a simple way to authenticate to the Spotify Web API using OmniAuth with OAuth2.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,14 +18,16 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
You'll need to register an app on Spotify, you can do this here - https://developer.spotify.com/my-applications/#!/
|
21
|
+
You'll need to register an app on Spotify, you can do this here - https://developer.spotify.com/my-applications/#!/applications
|
22
22
|
|
23
23
|
Usage of the gem is very similar to other OmniAuth strategies.
|
24
24
|
You'll need to add your app credentials to `config/initializers/omniauth.rb`:
|
25
25
|
|
26
26
|
```ruby
|
27
|
+
keys = Rails.application.secrets
|
28
|
+
|
27
29
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
28
|
-
provider :spotify, '
|
30
|
+
provider :spotify, keys.spotify['client_id'], keys.spotify['client_secret'], scope: 'playlist-read-private user-read-private user-read-email'
|
29
31
|
end
|
30
32
|
```
|
31
33
|
|
@@ -35,60 +37,84 @@ Read more about scopes here: https://developer.spotify.com/web-api/using-scopes/
|
|
35
37
|
Or with Devise in `config/initializers/devise.rb`:
|
36
38
|
|
37
39
|
```ruby
|
38
|
-
|
40
|
+
keys = Rails.application.secrets
|
41
|
+
|
42
|
+
config.omniauth :spotify, keys.spotify['client_id'], keys.spotify['client_secret'], scope: 'playlist-read-private user-read-private user-read-email'
|
39
43
|
```
|
40
44
|
|
45
|
+
## Forcing a Permission-Request Dialog
|
46
|
+
|
47
|
+
If a user has given permission for an app to access a scope, that permission won't be asked again unless the user revokes access.
|
48
|
+
In these cases, authorization sequences proceed without user interation.
|
49
|
+
|
50
|
+
To force a permission dialog being shown to the user, which also makes it possible for them to switch Spotify accounts,
|
51
|
+
set either `request.env['rack.session'][:ommiauth_spotify_force_approval?]` or `flash[:ommiauth_spotify_force_approval?]` (Rails apps only)
|
52
|
+
to a truthy value on the request that performs the Omniauth redirection.
|
53
|
+
|
41
54
|
## Auth Hash Schema
|
42
55
|
|
43
|
-
|
56
|
+
* Authorization data is available in the `request.env['omniauth.auth'].credentials` -- a hash that also responds to
|
57
|
+
the `token`, `refresh_token`, `expires_at`, and `expires` methods.
|
44
58
|
|
45
|
-
|
59
|
+
```ruby
|
60
|
+
{
|
61
|
+
"token" => "xxxx",
|
62
|
+
"refresh_token" => "xxxx",
|
63
|
+
"expires_at" => 1403021232,
|
64
|
+
"expires" => true
|
65
|
+
}
|
66
|
+
```
|
46
67
|
|
47
|
-
*
|
48
|
-
* `user-read-private` affects the value of `name` (if the scope is
|
49
|
-
missing it will reflect `username`) and the presence of
|
50
|
-
`image`
|
68
|
+
* Information about the authorized Spotify user is available in the `request.env['omniauth.auth'].info` hash. e.g.
|
51
69
|
|
52
70
|
```ruby
|
53
|
-
{
|
54
|
-
:provider => "spotify",
|
55
|
-
:uid => "1111111111",
|
56
|
-
:info => {
|
71
|
+
{
|
57
72
|
:name => "Claudio Poli",
|
58
|
-
:nickname =>
|
73
|
+
:nickname => "SomeName",
|
59
74
|
:email => "claudio@icorete.ch",
|
60
|
-
:urls => {
|
61
|
-
:image =>
|
75
|
+
:urls => {"spotify" => "https://open.spotify.com/user/1111111111"},
|
76
|
+
:image => "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/t1.0-1/s320x320/301234_1962753760624_625151598_n.jpg",
|
77
|
+
:birthdate => Mon, 01 Mar 1993, # Date class
|
78
|
+
:country_code => "IT",
|
79
|
+
:product => "open",
|
80
|
+
:follower_count => 10
|
81
|
+
}
|
82
|
+
```
|
83
|
+
|
84
|
+
The username/nickname is also available via a call to `request.env['omniauth.auth'].uid`.
|
85
|
+
|
86
|
+
* Unless the `user-read-private` scope is included, the `birthdate`, `country`, `image`, and `product` fields may be `nil`,
|
87
|
+
and the `name` field will be set to the username/nickname instead of the display name.
|
88
|
+
* The email field will be nil if the 'user-read-email' scope isn't included.
|
89
|
+
|
62
90
|
|
91
|
+
* The raw response to the `me` endpoint call is also available in `request.env['omniauth.auth'].extra['raw_info']`. e.g.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
{
|
95
|
+
"country" => "IT",
|
96
|
+
"display_name" => "Claudio Poli",
|
97
|
+
"birthdate" => "1993-03-01",
|
98
|
+
"email" => "claudio@icorete.ch",
|
99
|
+
"external_urls" => {
|
100
|
+
"spotify" => "https://open.spotify.com/user/1111111111"
|
63
101
|
},
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
:expires_at => 1403021232,
|
68
|
-
:expires => true
|
102
|
+
"followers" => {
|
103
|
+
"href" => nil,
|
104
|
+
"total" => 10
|
69
105
|
},
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
},
|
78
|
-
:href => "https://api.spotify.com/v1/users/1111111111",
|
79
|
-
:id => "1111111111",
|
80
|
-
:images => [
|
81
|
-
{
|
82
|
-
"height" => nil,
|
83
|
-
"url" => "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/t1.0-1/s320x320/301234_1962753760624_625151598_n.jpg",
|
84
|
-
"width" => nil
|
85
|
-
}
|
86
|
-
],
|
87
|
-
:product => "open",
|
88
|
-
:type => "user",
|
89
|
-
:uri => "spotify:user:1111111111"
|
106
|
+
"href" => "https://api.spotify.com/v1/users/1111111111",
|
107
|
+
"id" => "1111111111",
|
108
|
+
"images" => [
|
109
|
+
{
|
110
|
+
"height" => nil,
|
111
|
+
"url" => "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/t1.0-1/s320x320/301234_1962753760624_625151598_n.jpg",
|
112
|
+
"width" => nil
|
90
113
|
}
|
91
|
-
|
114
|
+
],
|
115
|
+
"product" => "open",
|
116
|
+
"type" => "user",
|
117
|
+
"uri" => "spotify:user:1111111111"
|
92
118
|
}
|
93
119
|
|
94
120
|
```
|
data/lib/omniauth-spotify.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'omniauth/strategies/oauth2'
|
2
|
+
require 'date'
|
2
3
|
|
3
4
|
module OmniAuth
|
4
5
|
module Strategies
|
5
6
|
class Spotify < OmniAuth::Strategies::OAuth2
|
6
7
|
# Give your strategy a name.
|
7
8
|
option :name, 'spotify'
|
9
|
+
|
10
|
+
FORCE_APPROVAL_KEY = 'ommiauth_spotify_force_approval?'.freeze
|
8
11
|
|
9
12
|
# This is where you pass the options you would pass when
|
10
13
|
# initializing your consumer from the OAuth gem.
|
@@ -23,13 +26,19 @@ module OmniAuth
|
|
23
26
|
|
24
27
|
info do
|
25
28
|
{
|
26
|
-
#
|
27
|
-
#
|
29
|
+
# Unless the 'user-read-private' scope is included, the birthdate, country, image, and product fields may be nil,
|
30
|
+
# and the name field will be set to the username/nickname instead of the display name.
|
31
|
+
# The email field will be nil if the 'user-read-email' scope isn't included.
|
32
|
+
#
|
28
33
|
:name => raw_info['display_name'] || raw_info['id'],
|
29
34
|
:nickname => raw_info['id'],
|
30
35
|
:email => raw_info['email'],
|
31
36
|
:urls => raw_info['external_urls'],
|
32
|
-
:image => image_url
|
37
|
+
:image => image_url,
|
38
|
+
:birthdate => raw_info['birthdate'] && Date.parse(raw_info['birthdate']),
|
39
|
+
:country_code => raw_info['country'],
|
40
|
+
:product => raw_info['product'],
|
41
|
+
:follower_count => raw_info['followers']['total']
|
33
42
|
}
|
34
43
|
end
|
35
44
|
|
@@ -50,6 +59,10 @@ module OmniAuth
|
|
50
59
|
def raw_info
|
51
60
|
@raw_info ||= access_token.get('me').parsed
|
52
61
|
end
|
62
|
+
|
63
|
+
def authorize_params
|
64
|
+
super.tap { |params| params[:show_dialog] = true if session.delete(FORCE_APPROVAL_KEY) || defined?(Rails) && session[:flash]['flashes'][FORCE_APPROVAL_KEY] }
|
65
|
+
end
|
53
66
|
|
54
67
|
def callback_url
|
55
68
|
if @authorization_code_from_signed_request_in_cookie
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-spotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Poli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.6.8
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: OmniAuth strategy for Spotify
|