11# frozen_string_literal: true
22
3- require ' date'
4- require ' omniauth-oauth2'
3+ require " date"
4+ require " omniauth-oauth2"
55
66module OmniAuth
77 module Strategies
88 # OmniAuth strategy for Spotify OAuth2.
99 class Spotify < OmniAuth ::Strategies ::OAuth2
10- option :name , ' spotify'
10+ option :name , " spotify"
1111
12- FORCE_APPROVAL_KEY = ' omniauth_spotify_force_approval?'
13- LEGACY_FORCE_APPROVAL_KEY = ' ommiauth_spotify_force_approval?'
12+ FORCE_APPROVAL_KEY = " omniauth_spotify_force_approval?"
13+ LEGACY_FORCE_APPROVAL_KEY = " ommiauth_spotify_force_approval?"
1414
1515 option :client_options ,
16- site : ' https://api.spotify.com' ,
17- authorize_url : ' https://accounts.spotify.com/authorize' ,
18- token_url : ' https://accounts.spotify.com/api/token' ,
19- connection_opts : {
20- headers : {
21- user_agent : ' icoretech-omniauth-spotify gem' ,
22- accept : ' application/json' ,
23- content_type : ' application/json'
24- }
25- }
26-
27- uid { raw_info [ 'id' ] }
16+ site : " https://api.spotify.com" ,
17+ authorize_url : " https://accounts.spotify.com/authorize" ,
18+ token_url : " https://accounts.spotify.com/api/token" ,
19+ connection_opts : {
20+ headers : {
21+ user_agent : " icoretech-omniauth-spotify gem" ,
22+ accept : " application/json" ,
23+ content_type : " application/json"
24+ }
25+ }
26+
27+ uid { raw_info [ "id" ] }
2828
2929 info do
3030 {
31- name : raw_info [ ' display_name' ] || raw_info [ 'id' ] ,
32- nickname : raw_info [ 'id' ] ,
33- email : raw_info [ ' email' ] ,
34- urls : raw_info [ ' external_urls' ] ,
31+ name : raw_info [ " display_name" ] || raw_info [ "id" ] ,
32+ nickname : raw_info [ "id" ] ,
33+ email : raw_info [ " email" ] ,
34+ urls : raw_info [ " external_urls" ] ,
3535 image : image_url ,
36- birthdate : parse_birthdate ( raw_info [ ' birthdate' ] ) ,
37- country_code : raw_info [ ' country' ] ,
38- product : raw_info [ ' product' ] ,
39- follower_count : raw_info . dig ( ' followers' , ' total' )
36+ birthdate : parse_birthdate ( raw_info [ " birthdate" ] ) ,
37+ country_code : raw_info [ " country" ] ,
38+ product : raw_info [ " product" ] ,
39+ follower_count : raw_info . dig ( " followers" , " total" )
4040 } . compact
4141 end
4242
4343 credentials do
4444 {
45- ' token' => access_token . token ,
46- ' refresh_token' => access_token . refresh_token ,
47- ' expires_at' => access_token . expires_at ,
48- ' expires' => access_token . expires? ,
49- ' scope' => token_scope
45+ " token" => access_token . token ,
46+ " refresh_token" => access_token . refresh_token ,
47+ " expires_at" => access_token . expires_at ,
48+ " expires" => access_token . expires? ,
49+ " scope" => token_scope
5050 } . compact
5151 end
5252
5353 extra do
5454 {
55- ' raw_info' => raw_info
55+ " raw_info" => raw_info
5656 }
5757 end
5858
5959 def raw_info
60- @raw_info ||= access_token . get ( ' v1/me' ) . parsed
60+ @raw_info ||= access_token . get ( " v1/me" ) . parsed
6161 end
6262
6363 def image_url
64- raw_info . fetch ( ' images' , [ ] ) . first &.fetch ( ' url' , nil )
64+ raw_info . fetch ( " images" , [ ] ) . first &.fetch ( " url" , nil )
6565 end
6666
6767 def authorize_params
@@ -71,18 +71,18 @@ def authorize_params
7171 end
7272
7373 def request_phase
74- options [ :authorize_params ] [ :show_dialog ] = request . params [ ' show_dialog' ] if request . params . key? ( ' show_dialog' )
74+ options [ :authorize_params ] [ :show_dialog ] = request . params [ " show_dialog" ] if request . params . key? ( " show_dialog" )
7575 super
7676 end
7777
7878 def callback_url
79- return '' if @authorization_code_from_signed_request
79+ return "" if @authorization_code_from_signed_request
8080
8181 options [ :callback_url ] || super
8282 end
8383
8484 def query_string
85- return '' if request . params [ ' code' ]
85+ return "" if request . params [ " code" ]
8686
8787 super
8888 end
@@ -91,7 +91,7 @@ def query_string
9191
9292 def token_scope
9393 token_params = access_token . respond_to? ( :params ) ? access_token . params : { }
94- token_params [ ' scope' ] || ( access_token [ ' scope' ] if access_token . respond_to? ( :[] ) )
94+ token_params [ " scope" ] || ( access_token [ " scope" ] if access_token . respond_to? ( :[] ) )
9595 end
9696
9797 def force_approval_requested?
@@ -102,7 +102,7 @@ def force_approval_requested?
102102 end
103103
104104 def flash_force_approval? ( key )
105- flashes = session . dig ( :flash , ' flashes' ) || session . dig ( ' flash' , ' flashes' )
105+ flashes = session . dig ( :flash , " flashes" ) || session . dig ( " flash" , " flashes" )
106106 !!flashes &.[]( key )
107107 end
108108
0 commit comments