jkistler
jkistler

Reputation: 796

Sonos API Redirect URI

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.

Upvotes: 5

Views: 783

Answers (2)

RiccardoCh
RiccardoCh

Reputation: 1120

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()
    }
}

Upvotes: 0

Flo
Flo

Reputation: 146

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.

Upvotes: 2

Related Questions