I would use the following script
- Configure a local web server to retrieve code from oauth redirect user
- Set the redirect_uri stream for the local web server and get the auth url
- Open auth url browser for user
- Get the code from the local web server and exchange the oauth code
Here are some details with the code.
Configure a local web server to retrieve an HTTP request
Below is an example of setting up a local web server with NanoHttpd
public class OAuthServer extends NanoHTTPD { public DebugServer() { super(8080); } @Override public Response serve(String uri, Method method, Map<String, String> header, Map<String, String> parms, Map<String, String> files) { bool error = false string code = null
Set the redirect_uri stream for the local web server and get the auth url
String url = flow.newAuthorizationUrl().setRedirectUri("http://localhost:8080").build();
Open auth url browser for user
Get the code from the local web server and exchange the oauth code
Now the user will approve OAuth from the web browser and send the code to the local web server that we just started. Now that we have the code extracted from the local web server, we can analyze it in int and authenticate and authorize with it!
Hope this helps
source share