SoundCloudSwift provides tools for authentication that you can use within your apps.
- Create an
Oauth2
object (handler) passing theOauth2Config
which includes (client id, client secret and redirect uri) provided by the API.
let oauth2: Oauth2 = Oauth2(config: Oauth2Config(clientId: clientId, clientSecret: clientSecret, redirectUri: redirect), scope: .All)
- Subscribe to the Oauth2 signal to listen for status changes during the Oauth2 flow:
oauth2.signal.observeNext { (next) -> () in
switch next {
case .OpenUrl(let url): // Open url
case .NewSession(let session): // Authentication completed
}
// Status events
}
Notice the kind of events that are sent:
- OpenUrl: When this event is sent you have to open the provided link in your webview.
- NewSession: When this event is received we have a new user session that we can use to authenticate API requests.
- Connect your webview with
Oauth2
sending redirect URLs from the browser:
oauth2.validate(url: newUrl)
- Start the Oauth2 flow with
oauth2.start()
If you're going to use the native Webkit we provide you with a class, Oauth2WebView
that automatizes the process. This class is initialized with the Oauth2 object and internally connects the Webview delegate with that object.
Your only responsibility in that case is listening to next events. That's all!
let viewController: Oauth2WebViewController = Oauth2WebViewController(oauth2: oauth2, scope: .All)
oauth2.signal.observeNext { (next) -> () in
print(next)
}
These systems don't support Webview, thus we cannot execute the authentication flow in these platforms. What we can do instead if sharing the authentication information from an iOS device or from OSX.
watchOS
tvOS
Apple doesn't provide any Connectivity framework to share data between iOS and tvOS. To solve this problem you can go to HTTP/TCP/Bluetooth custom solutions that you'll have to implement on your own
We thought about implementing a custom sharing component for SoundCloudSwift but due to the fact that tvOS is in its early versions we preferred to wait for next version to see Apple's strategy around this topic.