I have a question about the Sonos API authentication redirect URI. In previous projects I have used a redirect URI that my native application can intercept. Such as myApp://auth-code
. That does not appear to be possible with the Sonos API as it expects the redirect URI to be publicly routable and HTTPS. Must I have my own server that sits between my native client and the Sonos API? I have a feeling I may be missing something simple here. Thanks for your time.
Asked
Active
Viewed 663 times
4

jkistler
- 786
- 5
- 11
-
Thanks for the feedback. Currently, we only support publicly routable uris. We'll let everyone know if that changes. – Matt Welch Sep 14 '18 at 13:00
-
2@MattWelch I'd like to see this as well. It's pretty common everywhere else. See https://www.oauth.com/oauth2-servers/redirect-uris/redirect-uris-native-apps/ – Klaas Sep 15 '18 at 11:12
-
@Klaas do you have any good ideas for a workaround? As of now, everything I have came up with involves creating my own backend just to transfer tokens between my native app and the Sonos API. But this seems like way more work then its worth. – jkistler Sep 17 '18 at 16:45
-
my idea right now is to setup a simple dummy server as an endpoint that does nothing, let the user do the authentication within a WKWebView and just grab the needed code parameter on iOS when the web view gets redirected to the server. I‘ll guess Sonos will rather sooner than later allow non https url schemes?! – Klaas Sep 17 '18 at 23:02
-
For our php-based sonos cloud api, we prepared it as you wrote - having a public "dummy" endpoint that will be used to route the data back to the private local application. https://github.com/hubwareHouse/sonos contains some code... – Tobias Sep 27 '18 at 04:57
2 Answers
1
Just have a dummy endpoint e.g. firebase cloud function that does a redirect to your own custom scheme, e.g., location.href="myapp-scheme://..."
make sure to append the query parameters.
you can also avoid opening an external browser by embedding a safari webview.

Flo
- 136
- 7
0
If you use a WebView to show Sonos auth page you can detect the url of the WebView displayed, then you can detect when the WebView is loading the Redirect Uri, get it (with the code) and do your stuff. Here an example using Kotlin:
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {}
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
// Here you can get url and then Sonos code
if (url != null && url.contains(redirectUri) && url.contains("&code=")) doStuff()
}
}

RiccardoCh
- 1,060
- 1
- 13
- 24