1

I have two servers.

The first one is running a headless Kotlin/JVM program, and is not accessible for the "client", so it's not possible to authenticate on this server directly. It uploads given video on YouTube.

The second one is web interface on Python, which is accessible for the client. The client is authenticating with OAuth 2 on this server, and the server gets the following data:

{"token": "...", "refresh_token": "...", "token_uri": "https://www.googleapis.com/oauth2/v3/token", "client_id": "....apps.googleusercontent.com", "client_secret": "...", "scopes": ["https://www.googleapis.com/auth/youtube.force-ssl"]}

I want to pass it to the second server, but I don't know how to pass these parameters to the Google's Oauth library. If I do it like this:

        val credential = Credential.Builder(BearerToken.authorizationHeaderAccessMethod())
            .setTokenServerUrl(GenericUrl("https://www.googleapis.com/oauth2/v3/token"))
            .setTransport(httpTransport)
            .setJsonFactory(jsonFactory)
            .clientAuthentication() // Where to get the parameter?
            .build()

        credential.accessToken = "..."
        credential.refreshToken = "..."

It throws an exception if I don't set the clientAuthentication, but I don't know how to construct it:

Exception in thread "main" java.lang.IllegalArgumentException: Please use the Builder and call setJsonFactory, setTransport, setClientAuthentication and setTokenServerUrl/setTokenServerEncodedUrl

Is there any simple way to pass token parameters?

artem
  • 16,382
  • 34
  • 113
  • 189
  • If user is already authenticated on the Python server then I wonder why you again want to authenticate user on second server (Kotlin)? I suggest to pass token information or whatever data required in request body or custom header(s) to the Kotlin server. – Naqi Apr 12 '20 at 15:51
  • @Naqi token lives only about 60 minutes, so I need to periodically refresh it with the refresh_token. – artem Apr 12 '20 at 17:06
  • you can't pass token by setting to Credential. You need to obtain the token and then pass that in the request – Salim May 20 '20 at 15:35

0 Answers0