Skip to content

Commit 8f95bce

Browse files
authored
iOS: Remove dependency on legacy Spotify SDK (#32)
* removed spotify sdk dependency and create oauth url by hand * changed if to guard statement * cleanup and use urlcomponents to build url Co-authored-by: Manuel macOS <>
1 parent 049f7da commit 8f95bce

4 files changed

+21
-22
lines changed

install-ios.sh

-9
This file was deleted.

plugin.xml

-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
</platform>
2828

2929
<platform name="ios">
30-
<hook type="before_plugin_install" src="install-ios.sh"/>
31-
3230
<config-file target="config.xml" parent="/*">
3331
<feature name="SpotifyOAuth">
3432
<param name="ios-package" value="SpotifyOAuthPlugin"/>
@@ -37,8 +35,6 @@
3735

3836
<dependency id="cordova-plugin-add-swift-support" version="2.0.2"/>
3937

40-
<framework src="src/ios/spotify-sdk/SpotifyAuthentication.framework" custom="true"/>
41-
4238
<source-file src="src/ios/SpotifyOAuthPlugin.swift"/>
4339
<header-file src="src/ios/SpotifyOAuth-Bridging-Header.h"/>
4440
</platform>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#import <SpotifyAuthentication/SpotifyAuthentication.h>
1+

src/ios/SpotifyOAuthPlugin.swift

+20-8
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,27 @@ extension URL {
1313
private var currentNsObserver: AnyObject?
1414

1515
@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]
1719

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!)
2336

24-
let svc = SFSafariViewController(url: auth.spotifyWebAuthenticationURL())
2537
svc.delegate = self;
2638
svc.modalPresentationStyle = .overFullScreen
2739

@@ -32,7 +44,7 @@ extension URL {
3244
queue: nil
3345
) { note in
3446
let url = note.object as! URL
35-
guard auth.canHandle(url) else { return }
47+
guard url.absoluteString.contains("code") else { return }
3648

3749
svc.presentingViewController!.dismiss(animated: true, completion: nil)
3850
NotificationCenter.default.removeObserver(observer!)

0 commit comments

Comments
 (0)