auth0 / Lock.Android

Android Library to authenticate using Auth0 and with a Native Look & Feel
https://auth0.com/lock
MIT License
144 stars 82 forks source link

Unable to customize SDK networking client #656

Open NicholasGWK opened 1 year ago

NicholasGWK commented 1 year ago

Checklist

Description

Hello there! I commented on a PR a bit ago but figured I'd make an issue for better visibility in case the PR isn't monitored:

https://github.com/auth0/Lock.Android/pull/610#discussion_r1304689515

Essentially, allowing customization of the Auth0 SDK Networking client wasn't implemented when Lock was upgraded to use v2, with a note to come back to it. My team is currently trying to do some proxy configuration which would require customization of the network client so this would be a great thing to have fixed if it's still able to be considered a bugfix 😅

Thanks so much for looking!

Reproduction

Additional context

No response

Lock.Android version

Latest

Android version(s)

Doesn't matter

poovamraj commented 1 year ago

Hi @NicholasGWK this can be currently achieved this way

private fun showWebAuth() {
    val account = Auth0(getString(R.string.com_auth0_client_id), getString(R.string.com_auth0_domain))
    account.networkingClient = object : NetworkingClient {
        override fun load(url: String, options: RequestOptions): ServerResponse {
            TODO("Not yet implemented")
        }
    }
    login(account)
            .withScheme("demo")
            .start(this, loginCallback)
}

Does this help answer your query?

sabeehzaidi commented 1 year ago

Hey @poovamraj thank you for your response.

We did try that, as Nick mentioned in his query, when making requests at runtime, the NetworkingClient used is the default one instead of this newly customized one that we implemented using the same method you posted above. So the customized one is not being used.

Secondly, the proxy requires authorization so we wish to pass through a username and password with our requests to ensure requests go through. Any thoughts on this would be helpful. Thank you!

poovamraj commented 1 year ago

@sabeehzaidi can you share how this request is made. If the same instance of Auth0 is used then this shouldn't happen.

The proxy implementation can be done based on how and which network stack you implement inside load function of the NetworkingClient.

sabeehzaidi commented 1 year ago

Hey @poovamraj it is the same interface implementation you mentioned above, but what I notice is that the calls end up in the DefaultHttpClient anyway. This is how I did it:

val auth = Auth0(BuildConfig.AUTH0_CLIENT_ID, BuildConfig.AUTH0_DOMAIN, BuildConfig.AUTH0_CONFIG_DOMAIN)
auth.networkingClient = CustomNetworkingClient()
class CustomNetworkingClient : NetworkingClient {

    override fun load(url: String, options: RequestOptions): ServerResponse {

        val proxy_port = 1081
        //...
        return ServerResponse(code, responseBody, responseHeaders)
    }
}

And this is the load() function of the DefaultClient that always seems to handle the calls regardless of the provided CustomNetworkingClient:

@Throws(IllegalArgumentException::class, IOException::class)
    override fun load(url: String, options: RequestOptions): ServerResponse {
        val response = prepareCall(url.toHttpUrl(), options).execute()

        return ServerResponse(
            response.code,
            response.body!!.byteStream(),
            response.headers.toMultimap()
        )
    }
poovamraj commented 1 year ago

@sabeehzaidi can you show how you call the login/authentication method. I can see that the object is instantiated right but not sure whether it is being used while calling the method.

sabeehzaidi commented 1 year ago

@poovamraj we then proceed to use the auth object with the Lock.newBuilder() as follows:

val builder = Lock.newBuilder(auth, presenter)
                .allowForgotPassword(false)
                .setDefaultDatabaseConnection(Auth0Authenticator.DATABASE_CONNECTION)
                .withUsernameStyle(UsernameStyle.EMAIL)
                .withAudience(BuildConfig.AUTH0_AUDIENCE)
                .withScope(Auth0Authenticator.AUTH0_SCOPES)
                .withScheme(BuildConfig.AUTH0_SCHEME)
                .closable(true)
                .allowSignUp(false)

        startActivity(builder.build(this).newIntent(this))

This proceeds to call the load() function of the DefaultClient()

poovamraj commented 1 year ago

@sabeehzaidi we are not able to reproduce this locally. Can you provide us a sample application which reproduces this issue? You can even use our sample application (app module) within the repo and create a fork

poovamraj commented 1 year ago

Hey all 👋 any update on this?

sabeehzaidi commented 1 year ago

Hey @poovamraj not yet but we'll get to it as soon as we can. Still in the pipeline as it will block future work.