Lock.Android icon indicating copy to clipboard operation
Lock.Android copied to clipboard

Unable to customize SDK networking client

Open NicholasGWK opened this issue 2 years ago • 9 comments

Checklist

  • [X] I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • [X] I have looked into the API documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] I agree to the terms within the Auth0 Code of Conduct.

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

  • Pass a customized networking client to the Auth0 v2 SDK instance that is passed to Lock
  • Make a request
  • The networking client used will be the default networking client, rather than the customized one

Additional context

No response

Lock.Android version

Latest

Android version(s)

Doesn't matter

NicholasGWK avatar Aug 30 '23 15:08 NicholasGWK

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?

poovamraj avatar Sep 11 '23 08:09 poovamraj

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!

sabeehzaidi avatar Sep 13 '23 06:09 sabeehzaidi

@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.

poovamraj avatar Sep 18 '23 13:09 poovamraj

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

sabeehzaidi avatar Sep 19 '23 16:09 sabeehzaidi

@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.

poovamraj avatar Sep 22 '23 08:09 poovamraj

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

sabeehzaidi avatar Sep 22 '23 15:09 sabeehzaidi

@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 avatar Sep 25 '23 08:09 poovamraj

Hey all 👋 any update on this?

poovamraj avatar Oct 23 '23 08:10 poovamraj

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.

sabeehzaidi avatar Oct 24 '23 15:10 sabeehzaidi