I'm developing a java application that integrates with google API (google sheets API)
I'm trying to follow an example provided in google developers website. Link: https://developers.google.com/sheets/api/quickstart/java#step_3_set_up_the_sample
They have used LocalServerReceiver to create the redirect uri as below.
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
It is being used inside com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp => authorize() method like this:
String redirectUri = receiver.getRedirectUri();
This is how receiver.getRedirectUri() generates the uri:
public String getRedirectUri() throws IOException {
server = HttpServer.create(new InetSocketAddress(port != -1 ? port : findOpenPort()), 0);
HttpContext context = server.createContext(callbackPath, new CallbackHandler());
server.setExecutor(null);
try {
server.start();
port = server.getAddress().getPort();
} catch (Exception e) {
Throwables.propagateIfPossible(e);
throw new IOException(e);
}
return "http://" + this.getHost() + ":" + port + callbackPath;
}
Since I'm running this in localhost, getRedirectUri() returns a url like this:
http://localhost:8888/Callback
What I want is to provide a custom url since I'm using ngrok to expose my localhost.
Ex: If I visit the url "paradise.au.ngrok.io" that will point to my localhost.
So I need to pass "paradise.au.ngrok.io" as redirect url.
Can someone help me out to achieve this?
Thanks.
You could simply use the
setHost()
method and set the redirect URI to your ngrok one.