Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support Google OAuth Client credentials without expiration time #1117

Conversation

dirkluijk
Copy link
Contributor

Change Description

Small fix for #1097 (cf024eb) to also allow credentials without an expiration time.

I only tested the previous fix with my own application default credentials, but it seems some tokens don't have the expiration time as it can be null.

Checklist

  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea.
  • Ensure the tests and linter pass
  • Appropriate documentation is updated (if necessary)

Relevant issues:

Additional fix for #1093.

@dirkluijk dirkluijk requested a review from a team January 15, 2023 15:19
@dirkluijk dirkluijk force-pushed the fix-google-credential-without-expiration-date branch from 8a4888b to 515cbfc Compare January 16, 2023 11:49
@shubha-rajan shubha-rajan added kokoro:force-run Add this label to force Kokoro to re-run the tests. tests: run labels Jan 17, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 17, 2023
@shubha-rajan shubha-rajan self-requested a review January 17, 2023 13:16
Copy link
Contributor

@shubha-rajan shubha-rajan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these are null pointer exceptions

@dirkluijk dirkluijk force-pushed the fix-google-credential-without-expiration-date branch from 515cbfc to 7d1b712 Compare January 17, 2023 13:24
@dirkluijk
Copy link
Contributor Author

@shubha-rajan for some reason, I cannot run the unit tests locally (had issues before, but I also remember having them running fine). I also tried ifconfig lo0 alias 127.0.0.2 up several times since I am running on macOS.

Anyway, I fixed the issue from the build.

Comment on lines 185 to 188
credential.getExpirationTimeMilliseconds() != null
? new Date(credential.getExpirationTimeMilliseconds())
: null
Copy link
Contributor

@shubha-rajan shubha-rajan Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we use an optional here instead of this ternary?

something like:

Optional<Long> expTime = Optional.ofNullable(credential.getExpirationTimeMilliseconds());

AccessToken accessToken = new AccessToken(
          credential.getAccessToken(),
          expTime.isPresent()
              ? new Date(expTime.get())
              : null
          );

@shubha-rajan
Copy link
Contributor

shubha-rajan commented Jan 17, 2023

@shubha-rajan for some reason, I cannot run the unit tests locally (had issues before, but I also remember having them running fine). I also tried ifconfig lo0 alias 127.0.0.2 up several times since I am running on macOS.

Anyway, I fixed the issue from the build.

Looks like there are still errors. The fix should just be to add a check before L398 to check whether tokenExpiration is null.

@shubha-rajan shubha-rajan added kokoro:force-run Add this label to force Kokoro to re-run the tests. tests: run labels Jan 17, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 17, 2023
@dirkluijk dirkluijk force-pushed the fix-google-credential-without-expiration-date branch from 7d1b712 to df7934a Compare January 17, 2023 14:06
@dirkluijk
Copy link
Contributor Author

All right, I pushed a fix, let's see.

@shubha-rajan shubha-rajan added kokoro:force-run Add this label to force Kokoro to re-run the tests. tests: run labels Jan 17, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 17, 2023
@shubha-rajan
Copy link
Contributor

shubha-rajan commented Jan 17, 2023

All right, I pushed a fix, let's see.

Looks like tests are passing this time. Did you see my note about using an Optional? It might be a nit, but I think it makes the code cleaner.

@dirkluijk dirkluijk force-pushed the fix-google-credential-without-expiration-date branch from df7934a to 38b6300 Compare January 17, 2023 14:55
@dirkluijk
Copy link
Contributor Author

Ah, I already dragged in jsr305 for nullability, but Optional makes more sense indeed (writing Kotlin for some time already). Will have a look at it.

@dirkluijk dirkluijk force-pushed the fix-google-credential-without-expiration-date branch from 38b6300 to 3c3666c Compare January 17, 2023 15:07
@dirkluijk
Copy link
Contributor Author

Applied your feedback! 🤞

@shubha-rajan shubha-rajan added kokoro:force-run Add this label to force Kokoro to re-run the tests. tests: run labels Jan 17, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 17, 2023
@shubha-rajan shubha-rajan added kokoro:force-run Add this label to force Kokoro to re-run the tests. tests: run labels Jan 17, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 17, 2023
@shubha-rajan shubha-rajan added kokoro:force-run Add this label to force Kokoro to re-run the tests. tests: run labels Jan 18, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 18, 2023
@shubha-rajan shubha-rajan merged commit 7b2aff4 into GoogleCloudPlatform:main Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants