Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: always attempt external auth refresh when fetching#11762

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 9 commits intomainfromstevenmasley/external_auth_refresh
Jan 25, 2024

Conversation

Emyrk
Copy link
Member

What this does

Refactors the external auth code to:

  • Always attempt to refresh when workspace agent fetches auth links. The agent uses this endpoint.
  • ValidateToken takes into accountExpirary information.

matifali reacted with thumbs up emoji
Comment on lines +186 to +188
if !link.Expiry.IsZero() && link.Expiry.Before(dbtime.Now()) {
return false, nil, nil
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Expired tokens should returninvalid

@@ -2030,78 +2030,25 @@ func (api *API) workspaceAgentsExternalAuth(rw http.ResponseWriter, r *http.Requ
return
}

if listen {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I hope my new flow is a bit easier to understand.

Basically there is 2 flows,listen and not listen. Iflisten is set to true, then the http handler will block until a valid auth token is found (this should probably be a websocket or something else idk).

Beforelisten andnot listen did not share any code, which is dumb because on a success, their code paths should be identical. So this refactor makes the two cases share the same code execution path when a valid auth token is found.

@EmyrkEmyrk requested a review fromjohnstcnJanuary 23, 2024 17:56
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

The change makes sense to me overall. Just need to make the tests pass.

@EmyrkEmyrkforce-pushed thestevenmasley/external_auth_refresh branch frome998ccb to189c8aeCompareJanuary 24, 2024 20:17
@EmyrkEmyrk requested a review fromjohnstcnJanuary 24, 2024 22:55
Comment on lines +2087 to 2094
if !valid {
// Set the previous token so the retry logic will skip validating the
// same token again. This should only be set if the token is invalid and there
// was no error. If it is invalid because of an error, then we should recheck.
previousToken = &externalAuthLink
handleRetrying(http.StatusOK, agentsdk.ExternalAuthResponse{
URL: redirectURL.String(),
})
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Had to do this to prevent re-validating the same token after the refresh attempt

Comment on lines +406 to +410
// If expiresIn is 0, then the token never expires.
expires := dbtime.Now().Add(time.Duration(body.ExpiresIn) * time.Second)
if body.ExpiresIn == 0 {
expires = time.Time{}
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This was another bug I found. If zero time was passed in, the token was considered immediately expired on our end.

Copy link
Member

Choose a reason for hiding this comment

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

That's probably a big one. IIRC GitHub often just gives you tokens with no expiry.

@Emyrk
Copy link
MemberAuthor

@johnstcn got it all passing

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

LGTM, some comments

Comment on lines 1626 to 1630
// We expect only 2. One from the initial "Refresh" attempt, and
// another from the first tick. Ideally this would be just one.
// In a failed test, you will likely see 9, as the last one
// gets canceled.
require.Equal(t, 1, validateCalls, "validate calls duplicated on same token")
Copy link
Member

Choose a reason for hiding this comment

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

Comment does not agree with belowrequire.Equal -- do we only expect 1 or 2?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I forgot to commit my comment diff 🤦.

It was two, then I decided to fix it and make it 1, since lower == better.

Screenshot from 2024-01-25 10-15-15

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed the typo...

Comment on lines +406 to +410
// If expiresIn is 0, then the token never expires.
expires := dbtime.Now().Add(time.Duration(body.ExpiresIn) * time.Second)
if body.ExpiresIn == 0 {
expires = time.Time{}
}
Copy link
Member

Choose a reason for hiding this comment

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

That's probably a big one. IIRC GitHub often just gives you tokens with no expiry.

@Emyrk
Copy link
MemberAuthor

That's probably a big one. IIRC GitHub often just gives you tokens with no expiry.

They do in the regular oauth flow for sure. I would guess this would be a big issue, but if it was, then wouldn't it break spectacularly?? So maybe in the device flow method there is an expiry 🤔

@EmyrkEmyrk merged commit0befc08 intomainJan 25, 2024
@EmyrkEmyrk deleted the stevenmasley/external_auth_refresh branchJanuary 25, 2024 16:54
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJan 25, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp