-
Notifications
You must be signed in to change notification settings - Fork 69
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
[GH-235] Refresh token on user level oauth (#235) #242
Conversation
Hello @vicky-demansol, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. |
Codecov Report
@@ Coverage Diff @@
## master #242 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 8 8
Lines 882 900 +18
======================================
- Misses 882 900 +18
Continue to review full report at Codecov.
|
Thanks, @vicky-demansol but this won't work. If I understand the code correctly, you are just not making any distinction between AccountLevel and UserLevel by removing the if. Both tokens come from different places (take a look to the This may work if you instead of getting the token from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach, but I fear it may not be handling all the cases correctly. Take a look at the comments.
server/http.go
Outdated
@@ -126,6 +126,12 @@ func (p *Plugin) completeUserOAuthToZoom(w http.ResponseWriter, r *http.Request) | |||
http.Error(w, err.Error(), http.StatusInternalServerError) | |||
return | |||
} | |||
} else { | |||
err = p.setUserToken(userID, token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems cleaner so far, but a few lines after (line 161) we are storing the token along the OAuthUserInfo. If we want to follow this pattern, we would need to refactor the token out of the OAuthUserInfo and fix whatever breaks from that.
Another solution would be to keep the current pattern, and just update the token when needed in the OAuthUserInfo structure when needed.
I leave up to you which path to take.
server/plugin.go
Outdated
@@ -175,7 +175,10 @@ func (p *Plugin) getActiveClient(user *model.User) (Client, string, error) { | |||
if err != nil { | |||
return nil, message, errors.New("could not decrypt OAuth access token") | |||
} | |||
|
|||
oldToken, err := p.getUserToken(user.Id) | |||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should handle the error, and remove this (I guess) debug lines.
server/plugin.go
Outdated
oldToken, err := p.getUserToken(user.Id) | ||
if err == nil { | ||
p.API.LogInfo(fmt.Sprintf("oldTokenIs===========================%s", *oldToken)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
if err != nil { | |
p.API.LogError("error while fetching token" , "error" , err.Error()) | |
return | |
} |
server/plugin.go
Outdated
if token == nil { | ||
return nil, errors.New("zoom app not connected") | ||
} | ||
return token, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return token, nil | |
return token, nil |
server/plugin.go
Outdated
func (p *Plugin) SetZoomUserToken(userID string, token *oauth2.Token) error { | ||
err := p.setUserToken(userID, token) | ||
if err != nil { | ||
return errors.Wrap(err, "could not set token") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error should be logged here or in the function getting called
server/zoom/oauth.go
Outdated
@@ -97,6 +97,7 @@ func (c *OAuthClient) GetMeeting(meetingID int) (*Meeting, error) { | |||
|
|||
func (c *OAuthClient) getUserViaOAuth(user *model.User) (*User, error) { | |||
url := fmt.Sprintf("%s/users/me", c.apiURL) | |||
|
|||
if c.isAccountLevel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unwanted change here
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some non blocking changes are pending , code looks good so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks!
@hanzei can you pls tell me what i have to Test in this PR? what is the expected result for this? |
@larkox Can you please help with tests steps here? I'm not sure how to reproduce crated a token that timed out. |
@dipak-demansol Yes |
I don't remember the timeline 100%, but in the old version, after you connect, if you wait for, I think, one hour, the token will be outdated and will force you to disconnect and connect again. In order to test it, have two environments: one with the new version, and one with the old, and connect to zoom (on user level oauth) roughly at the same time. Then let that simmer for a few hours (or overnight), and try to create a new meeting. The old version should fail, saying that the token is expired, or something like that, and the new version should work without issues. It would be useful also to have a third environment with account level app, to see if that is still working fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Tested With Two server, 1st server had a market zoom plugin on a Chrome browser and 2nd server had a PR_code zoom app on the Brave browser, after 6 hour issue generated in the 1st server but the same issue not generated in the 2nd server.
Additional Info :- with the chrome browser and 2nd server when i create zoom meeting and join the meeting then i'm successfully join the meeting but in the brew browser with the 2nd server when i perform the same step then zoom don't identify me as a host and its wait for start the meeting. i will discuss with dylan about that.
* [GH-235] Refresh token on user level oauth (#235) * [GH-235] Add Oauth User Level Refresh Token (#235) * [GH-235] Remove Unwanted Change * [GH-235] Add Error Log * [GH-235] Add Oauth User Level Refresh Token (#235) Co-authored-by: root <[email protected]> Co-authored-by: jupriano <[email protected]> Co-authored-by: Ben Schumacher <[email protected]>
Summary
i think is only move the refresh token outside "if isAccountLevel" but if the refresh token function only for account level, how we get user level token ?
Ticket Link
Fixes #235