VictorAlbertos / RxSocialConnect-Android

OAuth RxJava extension for Android.
Apache License 2.0
257 stars 22 forks source link

Document QueryString functionality #27

Open wispborne opened 7 years ago

wispborne commented 7 years ago

I just went down a rabbit hole of debugging that eventually led me to find that RxSocialConnect always assumes that the "oauth_verifier" parameter will be present.

If it's not present, it'll fail, even if the "oauth_token" parameter is present. This is the case on Goodreads - an example callback url from the api is "oauth://tir?oauth_token=xxxxxxxxxxxxx&authorize=1"

The solution for me was to replace the StrategyOAuth1 with a custom parser, which seems to be working fine, but it's quite non-intuitive. Maybe some documentation of this hidden feature is in order, assuming I have the facts straight.

For anyone else having the same problem, here's what my code looks like:

        QueryString.PARSER.replaceStrategyOAuth1(object : QueryStringStrategy {
            override fun extractCode(uri: Uri): String {
                return uri.getQueryParameter("oauth_token")
            }

            override fun extractError(uri: Uri): String? {
                return uri.getQueryParameter("error")
            }

        val goodReadsService = ServiceBuilder()
                .apiKey("xxxxxxxxxxxxxxxxxxxx")
                .apiSecret("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                .callback(GoodreadsApi.CALLBACK_URI)
                .build(GoodreadsApi())

        RxSocialConnect.with(activity, goodReadsService)
                .subscribe({ response ->
                    TimberKt.d { response.token().token }
                }, { error ->
                    TimberKt.e(error, { "Couldn't get token!" })
                })

Oh, and thank you for this lib, it is awesome.

VictorAlbertos commented 7 years ago

thanks @davidwhitman I'm planing to upgrade the internal dependency of Scribe soon, so I'll give some time to this issue.