Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to customize SDK networking client #656

Open
5 tasks done
NicholasGWK opened this issue Aug 30, 2023 · 9 comments
Open
5 tasks done

Unable to customize SDK networking client #656

NicholasGWK opened this issue Aug 30, 2023 · 9 comments
Labels

Comments

@NicholasGWK
Copy link

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • 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:

#610 (comment)

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 NicholasGWK added the bug This points to a verified bug in the code label Aug 30, 2023
@poovamraj
Copy link
Contributor

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 poovamraj added question and removed bug This points to a verified bug in the code labels Sep 11, 2023
@sabeehzaidi
Copy link

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
Copy link
Contributor

@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
Copy link

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
Copy link
Contributor

@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
Copy link

sabeehzaidi commented Sep 22, 2023

@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
Copy link
Contributor

@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
Copy link
Contributor

Hey all 👋 any update on this?

@sabeehzaidi
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants