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

Extend spo sp grant revoke with scope #5604

Closed
waldekmastykarz opened this issue Oct 29, 2023 · 3 comments
Closed

Extend spo sp grant revoke with scope #5604

waldekmastykarz opened this issue Oct 29, 2023 · 3 comments

Comments

@waldekmastykarz
Copy link
Member

Extends spo sp grant revoke with scope so that it's possible not only to remove the whole grant but also a specific scope.

Originally posted by @waldekmastykarz in #5055 (comment)

@waldekmastykarz
Copy link
Member Author

The underlying CSOM API SPOWebAppServicePrincipalPermissionGrant.DeleteObject() only supports removing the whole grant, rather than a specific scope. To remove just a specific scope, we'd have to look into the ability of updating scopes

@waldekmastykarz
Copy link
Member Author

The Scope property of a grant seems to be only a getter. With that, it seems that we won't be able to use CSOM to update scopes. We'd have to look some more into other options that we could potentially use for this.

@waldekmastykarz
Copy link
Member Author

OK, the following code seems to be working:

var ctx = new ClientContext("https://contoso-admin.sharepoint.com");
ctx.ExecutingWebRequest += (sender, e) => {
    e.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + accessToken;
};
var grantId = "abc";
var scopeToRevoke = "Mail.Read";

var sp = new SPOWebAppServicePrincipal(ctx);
var grantMgr = sp.GrantManager;
var grant = sp.PermissionGrants.GetByObjectId(grantId);
ctx.Load(grant);
ctx.ExecuteQuery();
grantMgr.Remove(grant.ClientId, grant.Resource, scopeToRevoke);
ctx.ExecuteQuery();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants