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

There is no proxy authentication #190

Closed
wonderfly opened this issue Jan 9, 2015 · 17 comments
Closed

There is no proxy authentication #190

wonderfly opened this issue Jan 9, 2015 · 17 comments
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@wonderfly
Copy link
Contributor

From ogregoire on January 11, 2013 01:56:14

Version of google-http-java-client (e.g. 1.5.0-beta)? 1.13.1-beta Java environment (e.g. Java 6, Android 2.3, App Engine)? Java 7 Describe the problem. I want my application to be able to access APIs behind a proxy that requires an authentication, but no proxy authentication is available. It is possible to set the proxy, but not to authenticate to it. How would you expect it to be fixed? Some parameters in the (Apache|Net)HttpTransport.Builder class should be set so we can use a proxy with authentication along with the proxy setting.

Original issue: http://code.google.com/p/google-http-java-client/issues/detail?id=190

@wonderfly wonderfly added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. imported priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 9, 2015
@wonderfly wonderfly self-assigned this Jan 9, 2015
@wonderfly
Copy link
Contributor Author

From yan...@google.com on January 24, 2013 06:23:40

For reference, here are the methods to set the proxy: http://javadoc.google-http-java-client.googlecode.com/hg/1.13.1-beta/com/google/api/client/http/javanet/NetHttpTransport.Builder.html#setProxy(java.net.Proxy) http://javadoc.google-http-java-client.googlecode.com/hg/1.13.1-beta/com/google/api/client/http/apache/ApacheHttpTransport.Builder.html#setProxy(org.apache.http.HttpHost) What the library lacks is a built-in way to do proxy authentication.

If you have sample Java code snippets that would be really helpful. Here's what I found with a quick Google search: http://stackoverflow.com/questions/8669726/java-proxy-authentication (looks very promising if it works) http://stackoverflow.com/questions/1626549/authenticated-http-proxy-with-java (a good work-around for now)

Status: Accepted
Labels: -Type-Defect Type-Enhancement Component-HTTP

@wonderfly
Copy link
Contributor Author

From yan...@google.com on January 24, 2013 06:30:24

Labels: Milestone-Version2.1.0

@wonderfly
Copy link
Contributor Author

From ogregoire on January 25, 2013 08:08:33

I believe you found exactly how to properly identify as the two ways you googled work properly on my behind-authenticated-proxy system.

@wonderfly
Copy link
Contributor Author

From yan...@google.com on February 06, 2013 15:54:01

Labels: -Milestone-Version2.1.0 Milestone-Version1.16.0

@wonderfly
Copy link
Contributor Author

From yan...@google.com on June 10, 2013 06:09:11

Labels: -Milestone-Version1.16.0 Milestone-Version1.17.0

@wonderfly
Copy link
Contributor Author

From yan...@google.com on July 26, 2013 03:12:18

Labels: -Milestone-Version1.17.0 Milestone-Version1.18.0

@wonderfly
Copy link
Contributor Author

From yan...@google.com on September 27, 2013 04:56:43

Labels: -Milestone-Version1.18.0

@wonderfly wonderfly removed their assignment May 20, 2016
@JustinBeckwith JustinBeckwith added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed 2–5 stars priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jun 6, 2018
@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Jun 8, 2018
@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Sep 11, 2018
@ajaaym
Copy link
Contributor

ajaaym commented Dec 10, 2018

Please follow this guide for setting proxy. closing this issue now. Please reopen if this doesn't help.

@ajaaym ajaaym closed this as completed Dec 10, 2018
@chanseokoh
Copy link
Contributor

@ajaaym please reopen. I have no permission to do so. As the original feature request says, this is about proxy authentication and not about setting proxy. The Oracle guide you linked just explains ways to set proxy. However, it does not say anything about setting up proxy authentication.

However, we did find some way to set up proxy authentication by directly controlling Apache HttpClient, which Google HTTP Client depends on: GoogleContainerTools/jib#1337 and GoogleContainerTools/jib#1366

@ajaaym
Copy link
Contributor

ajaaym commented Dec 19, 2018

@chanseokoh Please look at this answer sorry I forgot to add link about this in previous comment. Please let me know if this still doesn't work.

@chanseokoh
Copy link
Contributor

chanseokoh commented Dec 20, 2018

The accepted answer in the SO is to replace the single global Authenticator instance that affects everyone on a JVM, which is often infeasible to adopt, e.g., in a multi-threaded application, plugin environment, etc., where you do not wholely own or control the entire JVM. I think what is required is each individual Google HTTP client instance being able to flexibly and independently configure proxies and their auth, not modifying a global state JVM-wise or affecting each other. Does it make sense?

@chanseokoh
Copy link
Contributor

Reopen?

@ajaaym
Copy link
Contributor

ajaaym commented Dec 20, 2018

@chanseokoh this library uses Jre provided transport. Can you please describe your use case in more detail, which doesn't seems normal? This can also be achieved by using Proxy-Authroization header as described here use HttpRequestInitializer

@ajaaym ajaaym reopened this Dec 20, 2018
@chanseokoh
Copy link
Contributor

chanseokoh commented Dec 20, 2018

Thanks for opening this.

which doesn't seems normal?

I don't think my use case is unusual. The accepted answer in the SO just can't be used in multi-thread environment. (Agreed?) I am sure you will get that a multi-thread application is a normal use case. Also, as I said, the answer affects everyone on a JVM globally, which is not acceptable if you are developing, say a plugin where your code runs on a larger framework/platform, e.g., an IDE plugin separately installable into the IDE.

this library uses Jre provided transport.

I don't think this matters. IMO, the library should be able to send Proxy-Authorization (when required), e.g., even if no proxy-related system properties such as http.proxyHost are defined, or even if the JRE transport did not have any support for proxy. With Google HTTP client, I think I should be able to send Proxy-Authorization by calling some library API methods, and currently, you do have some API interface through which users can set proxies. From what I see, it is just that you don't yet have the API to set proxy auth.

For example, you do have ApacheHttpTransport.setProxy(), and ApacheHttpTransport.setProxySelector(). However, there's no API to set proxy auth. I think ApacheHttpTransport could add such methods. But there may be other places where these kinds of proxy methods would fit in too.

This can also be achieved by using Proxy-Authroization header as described here use HttpRequestInitializer

Sure, you can do whatever you want to achieve by directly and manually crafting HTTP headers at a low level, but then there would be no point of creating an HTTP library whose purpose is to provide high-level abstraction for ease of use and convenience, if the user has to manually do tedious low-level HTTP header manipulation. For example, according to your argument, what's the point of having methods such as HttpHeaders.setAuthorization() as a library, given that you can set whatever header you want with HttpHeaders.set(name, obj) or HttpHeaders.put(name, obj)? (Sorry, this is a rhetorical question.) Also note that, using HttpRequestInitializer will be very tedious if ProxySelector is configured to, say, connect to different proxies based on hosts.

That said, HttpHeaders doesn't have Proxy-Authorization: https://github.com/googleapis/google-http-java-client/blob/master/google-http-client/src/main/java/com/google/api/client/http/HttpHeaders.java#L59. Therefore, you really need to use the lowest-level header manipulation, e.g.,

request.getHeaders().set("Proxy-Authorization", Arrays.asList("Basic dXNlcjpwYXNz"))

to set Proxy-Authorization using HttpRequestInitializer.

And, given that ApacheHttpTransport already has setProxy() and setProxySelector(), which (I believe) already implemented its own standalone proxy support in it instead of entirely delegating the proxy business to JRE, I do think someone at Google did want to add first-class independent proxy support in the library. So, I think it should expand to complete the proxy support (i.e., add proxy auth support).

Sorry this was long, but I hope this makes things clear (for me too).

@chingor13 chingor13 self-assigned this Jan 3, 2019
@JustinBeckwith JustinBeckwith removed the triage me I really want to be triaged. label Jan 3, 2019
@chingor13
Copy link
Collaborator

In google-http-client 1.28.0, you will be able to actually use a modern Apache HttpClient implementation which supports proxy authentication. It will be available via google-http-client-apache (2.0.0). The ApacheHttpTransport will no longer crash with unsupported method exceptions when providing your own implementation as we removed dependence upon deprecated methods.

@charlesportwood
Copy link

charlesportwood commented Feb 9, 2021

@chingor13 @chanseokoh How do I use ApacheHttpTransport to configure proxy authentication? I have GMAIL service accounts and I need to build them with configured proxy authentication.

clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
* add App Engine API to pom.xml with test scope

* remove deprecated methods

* remove one more deprecated comment

* 1.9.71 appngine api
@mjovanc
Copy link

mjovanc commented Sep 15, 2022

I'm not sure this is relevant to this issue. But currently I experiencing issues such as "Failed to select a proxy". Isn't it possible without it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

9 participants