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

Check if a scope has been granted #379

Closed
Jericho opened this issue Nov 10, 2024 · 2 comments
Closed

Check if a scope has been granted #379

Jericho opened this issue Nov 10, 2024 · 2 comments
Assignees
Labels
Enhancement New feature or request
Milestone

Comments

@Jericho
Copy link
Owner

Jericho commented Nov 10, 2024

Sometimes it would be useful to be able to check if a given scope has been granted before invoking a method to avoid getting an exception similar to: Invalid access token, does not contain scopes:[<...the name of the scope(s)...>].

What I envision is something along these lines:

if (zoomNetClient.HasPermission("account:read:list_sub_accounts:master"))
{
    var paginatedAccounts = await zoomNetClient.Accounts.GetAllAsync(100, null, cancellationToken).ConfigureAwait(false);
}

Also, I envision a similar method to check if multiple scopes have been granted like so:

if (zoomNetClient.HasPermissions(new[] { "scope1", "scope2", "scope3" }))
{
    ... do something that requires multiple scopes ...
}
@Jericho Jericho added the Enhancement New feature or request label Nov 10, 2024
@Jericho Jericho added this to the 0.84.0 milestone Nov 10, 2024
@Jericho Jericho self-assigned this Nov 10, 2024
@Jericho
Copy link
Owner Author

Jericho commented Nov 11, 2024

One thing to keep in mind: the .Scopes property on the OAuthConnectionInfo class gets populated when a token is refreshed. This means that his property is NOT populated if the developer specifies a previously issued token when instantiating the connection info like in this example:

var clientId = "... your client ID ...";
var clientSecret = "... your client secret ...";
var accountId = "... your account id ...";
var accessToken = Environment.GetEnvironmentVariable("ZOOM_OAUTH_SERVERTOSERVER_ACCESSTOKEN", EnvironmentVariableTarget.User);

var connectionInfo = OAuthConnectionInfo.ForServerToServer(clientId, clientSecret, accountId, accessToken,
  (_, newAccessToken) =>
  {
    Environment.SetEnvironmentVariable("ZOOM_OAUTH_SERVERTOSERVER_ACCESSTOKEN", newAccessToken, EnvironmentVariableTarget.User);
  });
var zoomClient = new ZoomClient(connectionInfo);

This means that there is a possibility for the .Scopes property to be empty when the HasPermissions method is invoked. In this scenario, the code in HasPermissions must detect if the list of scopes is empty and, if so, to populate the .Scopes before proceeding. Unfortunately, I am not aware of any way that we can retrieve the list of scopes that have been granted other than to force the current token to be refreshed.

@Jericho
Copy link
Owner Author

Jericho commented Nov 15, 2024

🎉 This issue has been resolved in version 0.84.0 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant