omniauth-spotify 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdf552ae9587eab9fc42d3a29e18839e01fb4bd0
4
- data.tar.gz: 8b654a7a9799d359e68992d7bcd1243e3b8f1628
3
+ metadata.gz: 7b52e324f0a69229ce9d430055f440b5f86a69a3
4
+ data.tar.gz: 5c8f140624660c6af633a4e14f4f844e2fdc0170
5
5
  SHA512:
6
- metadata.gz: 91fd126d70e10c98765f4ca945bcbe4a03d90b7104757123215367d52ae097ada9ab62808a4b2c1a171d57bbf3bbe7954abd481a2f30a90b3c16fc8b9e4cca92
7
- data.tar.gz: 6bc427de60012737366b591719f6c228aed37e6404b8a5d826d6b12d9006dcd6120c4fb54b758a64bc644ea2025cce5b7d0404000e5bfa59feec4aa6ad67d6b6
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, 'app_id', 'app_secret', scope: 'playlist-read-private user-read-private user-read-email'
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
- config.omniauth :spotify, 'app_id', 'app_secret', scope: 'playlist-read-private user-read-private user-read-email'
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
- Here's an example auth hash, available in `request.env['omniauth.auth']`:
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
- Some of this fields depend on what scopes you ask, namely
59
+ ```ruby
60
+ {
61
+ "token" => "xxxx",
62
+ "refresh_token" => "xxxx",
63
+ "expires_at" => 1403021232,
64
+ "expires" => true
65
+ }
66
+ ```
46
67
 
47
- * `user-read-email` affects the presence of the `email` field
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 => 'SomeName',
73
+ :nickname => "SomeName",
59
74
  :email => "claudio@icorete.ch",
60
- :urls => {:spotify => "https://open.spotify.com/user/1111111111"},
61
- :image => 'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/t1.0-1/s320x320/301234_1962753760624_625151598_n.jpg'
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
- :credentials => {
65
- :token => "xxxx",
66
- :refresh_token => "xxxx",
67
- :expires_at => 1403021232,
68
- :expires => true
102
+ "followers" => {
103
+ "href" => nil,
104
+ "total" => 10
69
105
  },
70
- :extra => {
71
- :raw_info => {
72
- :country => "IT",
73
- :display_name => "Claudio Poli",
74
- :email => "claudio@icorete.ch",
75
- :external_urls => {
76
- :spotify => "https://open.spotify.com/user/1111111111"
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
  ```
@@ -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
- # display_name may be empty if user does not request
27
- # 'user-read-private'
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
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Spotify
3
- VERSION = "0.0.10"
3
+ VERSION = "0.0.11"
4
4
  end
5
5
  end
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.10
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: 2016-12-08 00:00:00.000000000 Z
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.5.1
63
+ rubygems_version: 2.6.8
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: OmniAuth strategy for Spotify