question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Send HTTP requests from Authenticator

See original GitHub issue

Hi,

I’d like to have a way to send some HTTP requests from the Authenticator because some authentication mechanisms need it in its workflow (for example: OAuth).

As workaround, for the moment,

  • I can create a new instance of OkHttpClient but I’m not sure it is a good practice, or
  • I can add a setHttpClient method in Authenticator:
MyAuthenticator authenticator = new MyAuthenticator();
OkHttpClient client = new OkHttpClient.Builder()
                .authenticator(authenticator)
                .build();
authenticator.setHttpClient(client);

But

        OkHttpClient client = new OkHttpClient.Builder()
                .authenticator(new MyAuthenticator(client))
                .build();

is not possible.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
swankjessecommented, Jun 19, 2022

One workaround is to use OkHttpClient.newBuilder():

  1. Create basicClient, an OkHttpClient that’s configured exactly as you want it, but with no Authenticator.
  2. Pass the basicClient to your Authenticator constructor
  3. Use basicClient.newBuilder(), add the authenticator, then call build() to create your authenticated client. Use this everywhere.
1reaction
swankjessecommented, Jul 25, 2016

Yep. That’s a big backwards-incompatible change. We’ll add it to the list of things to consider for okhttp4 in 2021.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] Define authentication setting on ... - GitHub
I connect to one API service with many requests. I now have to set the authentication settings on each request. But, because it's...
Read more >
Use additional context in Microsoft Authenticator notifications
Learn how to use additional context in MFA notifications.
Read more >
Authentication — Requests 2.28.1 documentation
Many web services that require authentication accept HTTP Basic Auth. This is the simplest kind, and Requests supports it straight out of the...
Read more >
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Additionally, for HTTP request methods that can cause ... (such as Cookies and HTTP Authentication) should be sent with requests.
Read more >
Sending API requests using cURL - Oracle Help Center
Authentication ; Sending a GET request; Sending a DELETE request; Sending a POST request; Sending a PUT request. Note: The code samples in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found