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

Update tokens when they get refreshed on User Level OAuth #235

Closed
larkox opened this issue Oct 20, 2021 · 3 comments · Fixed by #242
Closed

Update tokens when they get refreshed on User Level OAuth #235

larkox opened this issue Oct 20, 2021 · 3 comments · Fixed by #242
Assignees
Labels
Type/Bug Something isn't working
Milestone

Comments

@larkox
Copy link
Contributor

larkox commented Oct 20, 2021

Right now, on Account Level OAuth, OAuth tokens are updated when the token gets refreshed.

url = fmt.Sprintf("%s/users/%s", c.apiURL, user.Email)
currentToken, err := c.api.GetZoomSuperUserToken()
if err != nil {
return nil, errors.Wrap(err, "error getting zoom super user token")
}
tokenSource := c.config.TokenSource(context.Background(), currentToken)
updatedToken, err := tokenSource.Token()
if err != nil {
return nil, errors.Wrap(err, "error getting token from token source")
}
if updatedToken.AccessToken != currentToken.AccessToken {
kvErr := c.api.SetZoomSuperUserToken(updatedToken)
if kvErr != nil {
return nil, errors.Wrap(kvErr, "error setting new token")
}
}
c.token = updatedToken

This should be also done for User Level Apps. Also, it would be nice to check if all paths are correctly updating all the tokens (User Level and Account Level).

@larkox larkox added the Type/Bug Something isn't working label Oct 20, 2021
@jupriano
Copy link
Contributor

jupriano commented Nov 15, 2021

func​ (​c​ ​*OAuthClient​) ​getUserViaOAuth​(​user​ ​*​model.​User​) (​*User​, ​error​) { 
​        ​url​ ​:=​ ​fmt​.​Sprintf​(​"%s/users/me"​, ​c​.​apiURL​) 
​        ​currentToken​, ​err​ ​:=​ ​c​.​api​.​GetZoomSuperUserToken​() 
​         if​ ​err​ ​!=​ ​nil​ { 
​         ​   return​ ​nil​, ​errors​.​Wrap​(​err​, ​"error getting zoom super user token"​) 
​         } 
         ​tokenSource​ ​:=​ ​c​.​config​.​TokenSource​(​context​.​Background​(), ​currentToken​) 
​        ​updatedToken​, ​err​ ​:=​ ​tokenSource​.​Token​() 
​        ​if​ ​err​ ​!=​ ​nil​ { 
​            ​return​ ​nil​, ​errors​.​Wrap​(​err​, ​"error getting token from token source"​) 
​        } 
​        ​if​ ​updatedToken​.​AccessToken​ ​!=​ ​currentToken​.​AccessToken​ { 
​           ​kvErr​ ​:=​ ​c​.​api​.​SetZoomSuperUserToken​(​updatedToken​) 
           if​ ​kvErr​ ​!=​ ​nil​ { 
​                 ​return​ ​nil​, ​errors​.​Wrap​(​kvErr​, ​"error setting new token"​) 
​           } 
​       } 
       ​c​.​token​ ​=​ ​updatedToken
​       ​if​ ​c​.​isAccountLevel​ { 
​          ​url​ ​=​ ​fmt​.​Sprintf​(​"%s/users/%s"​, ​c​.​apiURL​, ​user​.​Email​)   ​
​        } 

Is it good to update like that ? @larkox

@larkox
Copy link
Contributor Author

larkox commented Nov 16, 2021

This seems the functionality for the account level oauth, not for the user level oauth. Feel free to create a PR so we can look better at the changelog.

jupriano pushed a commit to jupriano/mattermost-plugin-zoom that referenced this issue Nov 17, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-zoom that referenced this issue Nov 24, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-zoom that referenced this issue Dec 14, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-zoom that referenced this issue Dec 14, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-zoom that referenced this issue Dec 14, 2021
jupriano added a commit to jupriano/mattermost-plugin-zoom that referenced this issue Dec 14, 2021
jupriano added a commit to jupriano/mattermost-plugin-zoom that referenced this issue Dec 22, 2021
hanzei added a commit to jupriano/mattermost-plugin-zoom that referenced this issue Jan 25, 2022
larkox pushed a commit that referenced this issue Feb 7, 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 pushed a commit that referenced this issue 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 issue Jul 14, 2022
@mickmister mickmister reopened this Jul 28, 2022
@avas27JTG avas27JTG added this to the next milestone milestone Nov 14, 2023
@raghavaggarwal2308
Copy link
Contributor

@mickmister I think this issue has been fixed with PR #253. Can you please confirm that? If yes, can we close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type/Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants