@@ -13,15 +13,27 @@ extension URL {
13
13
private var currentNsObserver : AnyObject ?
14
14
15
15
@objc ( getCode: ) func getCode( _ command: CDVInvokedUrlCommand ) {
16
- let auth = SPTAuth . defaultInstance ( )
16
+ let clientid = command. argument ( at: 0 ) as! String
17
+ let redirectURL = command. argument ( at: 1 ) as! String
18
+ let requestedScopes = command. argument ( at: 4 ) as! [ String ]
17
19
18
- auth. clientID = command. argument ( at: 0 ) as! String
19
- auth. redirectURL = URL ( string: command. argument ( at: 1 ) as! String )
20
- auth. tokenSwapURL = URL ( string: command. argument ( at: 2 ) as! String )
21
- auth. tokenRefreshURL = URL ( string: command. argument ( at: 3 ) as! String )
22
- auth. requestedScopes = command. argument ( at: 4 ) as! Array
20
+ var components = URLComponents ( )
21
+ components. scheme = " https "
22
+ components. host = " accounts.spotify.com "
23
+ components. path = " /authorize "
24
+ components. queryItems = [
25
+ URLQueryItem ( name: " client_id " , value: clientid) ,
26
+ URLQueryItem ( name: " response_type " , value: " code " ) ,
27
+ URLQueryItem ( name: " redirect_uri " , value: redirectURL) ,
28
+ URLQueryItem ( name: " show_dialog " , value: " true " ) ,
29
+ URLQueryItem ( name: " scope " , value: requestedScopes. joined ( separator: " " ) ) ,
30
+ URLQueryItem ( name: " utm_source " , value: " spotify-sdk " ) ,
31
+ URLQueryItem ( name: " utm_medium " , value: " ios-sdk " ) ,
32
+ URLQueryItem ( name: " utm_campaign " , value: " ios-sdk " )
33
+ ]
34
+
35
+ let svc = SFSafariViewController ( url: components. url!)
23
36
24
- let svc = SFSafariViewController ( url: auth. spotifyWebAuthenticationURL ( ) )
25
37
svc. delegate = self ;
26
38
svc. modalPresentationStyle = . overFullScreen
27
39
@@ -32,7 +44,7 @@ extension URL {
32
44
queue: nil
33
45
) { note in
34
46
let url = note. object as! URL
35
- guard auth . canHandle ( url ) else { return }
47
+ guard url . absoluteString . contains ( " code " ) else { return }
36
48
37
49
svc. presentingViewController!. dismiss ( animated: true , completion: nil )
38
50
NotificationCenter . default. removeObserver ( observer!)
0 commit comments