cdap icon indicating copy to clipboard operation
cdap copied to clipboard

Add support for OAuth provider APIs to return long-lived access tokens

Open Awk34 opened this issue 10 months ago • 1 comments

This adds methods for storing long-lived access tokens in the secure store. This also adds support for OAuth APIs to send only an access token when given a one-time-code.

Awk34 avatar Jun 06 '25 00:06 Awk34

please add a test when both refresh_token & access_token are returned and only refresh_token was written.

@itsankit-google @sahusanket I've been looking to add a test for this case, but as far as I can tell there are no similar unit tests that would modify the response from the backend before asserting behavior. The other methods in OAuthStore are tested in OAuthServiceTest.java. Is there a currently a way to change what the http response will return?

wclaiborne avatar Jun 12 '25 05:06 wclaiborne

please add a test when both refresh_token & access_token are returned and only refresh_token was written.

@itsankit-google @sahusanket I've been looking to add a test for this case, but as far as I can tell there are no similar unit tests that would modify the response from the backend before asserting behavior. The other methods in OAuthStore are tested in OAuthServiceTest.java. Is there a currently a way to change what the http response will return?

Hi, you can use powermock to mock static methods response, if you see in implementation methods we have used this method to execute http request : https://github.com/cdapio/common/blob/7d2ab9f010de01c01f42dfedcdd955a5bd841e5f/common-http/src/main/java/io/cdap/common/http/HttpRequests.java#L63

itsankit-google avatar Jun 24 '25 12:06 itsankit-google

please add a test when both refresh_token & access_token are returned and only refresh_token was written.

@itsankit-google @sahusanket I've been looking to add a test for this case, but as far as I can tell there are no similar unit tests that would modify the response from the backend before asserting behavior. The other methods in OAuthStore are tested in OAuthServiceTest.java. Is there a currently a way to change what the http response will return?

Hi, you can use powermock to mock static methods response, if you see in implementation methods we have used this method to execute http request : https://github.com/cdapio/common/blob/7d2ab9f010de01c01f42dfedcdd955a5bd841e5f/common-http/src/main/java/io/cdap/common/http/HttpRequests.java#L63

Thanks, I will do this in the follow-up PR.

I cherry-picked #15967 onto this one at your request

Awk34 avatar Jun 25 '25 21:06 Awk34