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

[GH-235] Refresh token on user level oauth (#235) #242

Merged
merged 8 commits into from
Feb 7, 2022

Conversation

jupriano
Copy link
Contributor

@jupriano jupriano commented Nov 17, 2021

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

@mattermod
Copy link
Contributor

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
Copy link

codecov bot commented Nov 17, 2021

Codecov Report

Merging #242 (9e85b76) into master (c4cda31) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #242   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files           8       8           
  Lines         882     900   +18     
======================================
- Misses        882     900   +18     
Impacted Files Coverage Δ
server/plugin.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4cda31...9e85b76. Read the comment docs.

@larkox
Copy link
Contributor

larkox commented Nov 17, 2021

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 getActiveClient function), and have to be handled slightly different.

This may work if you instead of getting the token from the getSuperUserToken you get it directly from the client (since it is already fetch from the database), but then you also have to distinguish where you store it. You must store the account level one as the superuser token, or the user level one on the user information.

@hanzei hanzei added the 2: Dev Review Requires review by a core committer label Nov 22, 2021
Copy link
Contributor

@larkox larkox left a 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)
Copy link
Contributor

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 {
Copy link
Contributor

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))
}
Copy link
Contributor

@sibasankarnayak sibasankarnayak Nov 29, 2021

Choose a reason for hiding this comment

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

Suggested change
}
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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")
Copy link
Contributor

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

@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove unwanted change here

@hanzei hanzei added Awaiting Submitter Action Blocked on the author 3: QA Review Requires review by a QA tester labels Nov 30, 2021
@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @BenLloydPearson @aspleenic

Copy link
Contributor

@sibasankarnayak sibasankarnayak left a 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.

Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@hanzei hanzei removed the 2: Dev Review Requires review by a core committer label Jan 25, 2022
@dipak-demansol
Copy link

@hanzei can you pls tell me what i have to Test in this PR? what is the expected result for this?

@hanzei hanzei added Awaiting Submitter Action Blocked on the author and removed Awaiting Submitter Action Blocked on the author labels Jan 26, 2022
@hanzei
Copy link
Collaborator

hanzei commented Jan 26, 2022

@larkox Can you please help with tests steps here? I'm not sure how to reproduce crated a token that timed out.

@hanzei hanzei added this to the v2.0.0 milestone Jan 26, 2022
@dipak-demansol
Copy link

@larkox Can you please help with tests steps here? I'm not sure how to reproduce crated a token that timed out.

@larkox @hanzei is this related to this? #239

@hanzei
Copy link
Collaborator

hanzei commented Jan 26, 2022

@dipak-demansol Yes

@larkox
Copy link
Contributor

larkox commented Jan 26, 2022

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.

Copy link

@dipak-demansol dipak-demansol left a 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.

@dipak-demansol dipak-demansol added QA Review Done PR has been approved by QA and removed 3: QA Review Requires review by a QA tester labels Feb 1, 2022
@hanzei hanzei added 4: Reviews Complete All reviewers have approved the pull request and removed QA Review Done PR has been approved by QA labels Feb 7, 2022
@larkox larkox merged commit 8a5a54d into mattermost:master Feb 7, 2022
mickmister pushed a commit that referenced this pull request Feb 24, 2022
* [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]>
mickmister added a commit that referenced this pull request Jul 14, 2022
mickmister added a commit that referenced this pull request Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update tokens when they get refreshed on User Level OAuth
6 participants