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/jwtSync #71

Closed
wants to merge 7 commits into from
Closed

fix/jwtSync #71

wants to merge 7 commits into from

Conversation

bguedel
Copy link

@bguedel bguedel commented Aug 17, 2021

fixes #68

per example in related issue; time sync issue can occur when setting issued at to be the current time. This sets the issued at to be 1 minute earlier to avoid this.

Tested locally for 2 days with no issues.

fixes spotify#68

per example in related issue; time sync issue can occur when setting issued at to be the current time. This sets the issued at to be 1 minute earlier to avoid this.

Tested locally for 2 days with no issues.
@bguedel
Copy link
Author

bguedel commented Aug 18, 2021

@henriquetruta thoughts?

@bguedel
Copy link
Author

bguedel commented Aug 24, 2021

@neonal Thoughts?

@bguedel
Copy link
Author

bguedel commented Sep 7, 2021

@henriquetruta thoughts?

i see you merged a couple of other PRs that were opened after mine. Wondering when we can get this merged; This is a blocker for my team to use this project ;(

@bguedel
Copy link
Author

bguedel commented Sep 20, 2021

@henriquetruta @neonal

any thoughts?

@bguedel
Copy link
Author

bguedel commented Sep 28, 2021

@neonal?? Looks like you merged a PR a few hours ago. Wondering if you can take a look at this PR??

Or can we get some guidance on if you guys actually accept PR from external?

@bguedel
Copy link
Author

bguedel commented Oct 11, 2021

@barbatron Can I get a quick look?

@bguedel
Copy link
Author

bguedel commented Oct 20, 2021

@barbatron looks like you are looking at some other prs; could i get a look see? maybe a comment or 3?

Copy link
Contributor

@barbatron barbatron left a comment

Choose a reason for hiding this comment

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

Somehow left my review pending 🤦 sorry about that!

@@ -74,7 +75,7 @@ public String getToken(final Integer appId) {
.setIssuer(String.valueOf(appId))
.signWith(signingKey, SIGNATURE_ALGORITHM)
.setExpiration(new Date(System.currentTimeMillis() + TOKEN_TTL))
.setIssuedAt(new Date())
.setIssuedAt(new Date(System.currentTimeMillis() - TOKEN_ISSUED))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a test for this?

If the current time is provided by a Supplier<long> then this could be more easily tested. Perhaps two constructors, one where this supplier is just () -> System.currentTimeMillis() and another ctor w @VisibleForTesting where tests can provide the supplier in order to get known values.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

(Don't feel strongly about it, apart from keeping them checks happy)

Copy link
Author

Choose a reason for hiding this comment

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

not really sure what i am testing here?
that the setter accepted my new time? or that the time was in fact 60 seconds before now?

I can for sure look into it though if you think a test is for sure needed.

Copy link
Author

@bguedel bguedel Oct 25, 2021

Choose a reason for hiding this comment

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

I can for sure understand getting another constructor in here so that people that dont have drift or care about it can ignore it.

added tests questionably; dont fully understand what else could be tested
@bguedel
Copy link
Author

bguedel commented Nov 9, 2021

@barbatron Sorry for the delay;

Added the supplier. I defaulted the main supplier to be the same as it is today so that people that update dont see any change to their code;

Added the "60000" to the tests; but not sure what we expect to be tested here; Effectively i am testing to see if a jwt is created when using the default and using a custom supplier; If you have any other ideas on what can be tested i am open to suggestion.

Right now the output is just a string; sooooo

@shaendler
Copy link
Contributor

@bguedel i also see this issue quite frequently in my app. using the 0.1.24 version.
Can you explain how as the library consumer i can control the isseuAt supplier? on my end, i am just creating a client

@barbatron can we urge this fix to merge?

@bguedel
Copy link
Author

bguedel commented Nov 16, 2021

@shaendler good call;

jwtToken = JwtTokenIssuer.fromPrivateKey(privateKey).getToken(appId);
<--- thats where this is actually being used.

which is essentially used by a request such as

final Request request = requestBuilder(path).build();

which is used by the GithubClient --> to which you create in your app.

so this solution wont actually work; though it gives some building blocks to work.

Open to suggestion on how we can make it work. Dont love pushing this all the way up to the GithubClient factory methods.

Otherwise we go back to hardcoding 60000 (60s)???

@bguedel
Copy link
Author

bguedel commented Nov 16, 2021

This is currently how we are using this (through those links)

//Spring @Configuration file
/**
     * Spotify github client.
     *
     * @return
     */
    @Bean
    public GitHubClient githubClient() throws IOException {
        byte[] decodedBytes = Base64.getDecoder().decode(gitHubProperties.getApp().getPrivateKey());
        FileUtils.writeByteArrayToFile(new File(PK_PATH), decodedBytes);

        return GitHubClient.create(
                URI.create("https://pathTo.github/api/v3"),
                FileUtils.getFile(PK_PATH),
                gitHubProperties.getApp().getAppId(),
                gitHubProperties.getApp().getInstallationId());
    }

@bguedel
Copy link
Author

bguedel commented Nov 16, 2021

ill make a pr right quick to change the default behavior to -60s and then still allow someone to override this;

i dont forsee this being an issue for current systems; this will solve the issue; but still give the chance to set this directly; if later someone wants to implement a way to use this feature deeper into the system.

Comment on lines 39 to 40
private static final long TOKEN_TTL = 600_000;
private static final long TOKEN_ISSUED = 60_000;
Copy link
Author

Choose a reason for hiding this comment

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

Fun Fact: Java totally allows _ in numbers for readability;

Copy link
Author

Choose a reason for hiding this comment

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

@bguedel
Copy link
Author

bguedel commented Nov 17, 2021

built this locally again and put it in my app; getting the error again; this supplier doesnt seem to be working the way i had expected.

@bguedel
Copy link
Author

bguedel commented Nov 30, 2021

so far this has worked locally; no more 401s

@bguedel
Copy link
Author

bguedel commented Dec 7, 2021

@barbatron Thoughts?

@bguedel
Copy link
Author

bguedel commented Dec 8, 2021

@barbatron Did you forget to submit your review again?

@bguedel
Copy link
Author

bguedel commented Dec 14, 2021

@barbatron hope you are having a good december;

Before you cut out for some awesome end of year bash, could i get a comment or 4, or maybe event an approval?

dont know why my pr is not really getting built/codecov

@wsguede
Copy link

wsguede commented Jan 6, 2022

Happy New Year Spotify team!

Could someone take a look at this and give some feedback or accept the pr?

@barbatron @henriquetruta @neonal

@bguedel
Copy link
Author

bguedel commented Jan 21, 2022

Hey Spotify team!

Just a friendly reminder; Looking to get this into master. Could I get some comments?
@barbatron @henriquetruta @neonal

@barbatron
Copy link
Contributor

barbatron commented Jan 27, 2022

Hey there @bguedel , I'm no longer with Spotify so I'm afraid I guess I can't be of help. Filtered out emails from the Spotify org due to the vast amount from other FOSS projects. I'm impressed with your tenacity, though! My team at Sp had lots to do and was getting even more on the plate, and without much buy-in to maintain these peripheral repos apart from dwindling spare time, I'm afraid it could be tricky to get attention. Best of luck though. Sorry I didn't get this ashore before I left back in October.

@bguedel
Copy link
Author

bguedel commented Feb 2, 2022

Hey @henriquetruta @neonal

Just wondering if you had any input on this change?

@bguedel
Copy link
Author

bguedel commented Mar 10, 2022

Wondering if we can get some eyes on this?

@ebk45
Copy link
Contributor

ebk45 commented Dec 22, 2023

Hi @bguedel.

We apologise for taking so long to get eyes on this PR, we haven't been able to maintain this library to the standard we would have liked to but this will be changing in the new year. If you could please get this rebased and we'll be prioritising all open PRs ready for review.

Thanks!

Ellie

@ebk45
Copy link
Contributor

ebk45 commented Feb 5, 2024

Hello,

As this PR is now stale and we've not had any new activity on it, we've decided to close it so we can keep track of active/more recent changes. We will leave the branch untouched in case you would like to reopen and rebase.

Thanks!

Ellie

@ebk45 ebk45 closed this Feb 5, 2024
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.

[Bug] Expired token unable to refresh
5 participants