diff --git a/docs/using-the-sdk/admin-sharepoint-apps.md b/docs/using-the-sdk/admin-sharepoint-apps.md index 94a69bdc4a..f7c167ff8c 100644 --- a/docs/using-the-sdk/admin-sharepoint-apps.md +++ b/docs/using-the-sdk/admin-sharepoint-apps.md @@ -181,14 +181,14 @@ After adding and deploying an app to the app catalog these API permissions need ```csharp // List the permission requests that are pending approval or rejection -ServicePrincipal principal = new(context); -List permissionRequests = await principal.GetPermissionRequestsAsync(); +var appManager = context.GetTenantAppManager(); +List permissionRequests = await appManager.ServicePrincipal.GetPermissionRequestsAsync(); // Approve a permission request -var result = await principal.ApprovePermissionRequestAsync(permissionRequests.First().Id.ToString()); +var result = await appManager.ServicePrincipal.ApprovePermissionRequestAsync(permissionRequests.First().Id.ToString()); // Deny a permission request -await principal.DenyPermissionRequestAsync(permissionRequests.First().Id.ToString()); +await appManager.ServicePrincipal.DenyPermissionRequestAsync(permissionRequests.First().Id.ToString()); ``` ## Tenant app catalog specific operations diff --git a/src/sdk/PnP.Core.Admin.Test/SharePoint/PermissionRequestsTests.cs b/src/sdk/PnP.Core.Admin.Test/SharePoint/PermissionRequestsTests.cs index 1db209541f..9e8a96501f 100644 --- a/src/sdk/PnP.Core.Admin.Test/SharePoint/PermissionRequestsTests.cs +++ b/src/sdk/PnP.Core.Admin.Test/SharePoint/PermissionRequestsTests.cs @@ -83,10 +83,14 @@ public async Task ApprovePermissionsRequestTest_Async() app = appManager.Add(packagePath, true); var deployResult = app.Deploy(false); - ServicePrincipal principal = new(context); - List permissionRequests = await principal.GetPermissionRequestsAsync(); + Assert.IsTrue(deployResult); - var result = await principal.ApprovePermissionRequestAsync(permissionRequests.First().Id.ToString()); + List permissionRequests = + await appManager.ServicePrincipal.GetPermissionRequestsAsync(); + + var result = + await appManager.ServicePrincipal.ApprovePermissionRequestAsync(permissionRequests.First().Id + .ToString()); Assert.IsNotNull(result); Assert.IsTrue(!string.IsNullOrWhiteSpace(result.ObjectId)); @@ -105,12 +109,27 @@ public async Task GetPermissionsRequestsTest_Async() //TestCommon.Instance.Mocking = false; using (PnPContext context = await TestCommon.Instance.GetContextAsync(TestCommonBase.TestSite)) { - ServicePrincipal principal = new(context); - List permissionRequests = await principal.GetPermissionRequestsAsync(); + ITenantApp app = null; + try + { + var appManager = context.GetTenantAppManager(); + app = appManager.Add(packagePath, true); + var deployResult = app.Deploy(false); + + Assert.IsTrue(deployResult); + + List permissionRequests = + await appManager.ServicePrincipal.GetPermissionRequestsAsync(); Assert.IsNotNull(permissionRequests); Assert.IsTrue(permissionRequests.Count > 0); } + finally + { + var retractResult = app.Retract(); + app.Remove(); + } + } } [TestMethod] @@ -125,10 +144,14 @@ public async Task DenyPermissionsRequestTest_Async() var appManager = context.GetTenantAppManager(); app = appManager.Add(packagePath, true); var deployResult = app.Deploy(false); - ServicePrincipal principal = new(context); - List permissionRequests = await principal.GetPermissionRequestsAsync(); - await principal.DenyPermissionRequestAsync(permissionRequests.First().Id.ToString()); + Assert.IsTrue(deployResult); + + List permissionRequests = + await appManager.ServicePrincipal.GetPermissionRequestsAsync(); + + await appManager.ServicePrincipal.DenyPermissionRequestAsync(permissionRequests.First().Id + .ToString()); } finally { diff --git a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/AppManager.cs b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/AppManager.cs index 08ab870d73..a418063d6e 100644 --- a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/AppManager.cs +++ b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/AppManager.cs @@ -242,6 +242,14 @@ public async Task AddAsync(string path, bool overwrite = false) return await AddAsync(bytes, fileInfo.Name, overwrite).ConfigureAwait(false); } + public IServicePrincipal ServicePrincipal + { + get + { + return new ServicePrincipal(this.context); + } + } + /// /// Executes an action and disposes if it's not the current context /// diff --git a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/IAppManager.cs b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/IAppManager.cs index c92b390a64..77d018b33c 100644 --- a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/IAppManager.cs +++ b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/IAppManager.cs @@ -82,5 +82,10 @@ public interface IAppManager : IAppOperations where T : IApp /// If true will overwrite an existing entry. /// An instance of the app. Task AddAsync(string path, bool overwrite = false); + + /// + /// Get the SharePoint Apps ServicePrincipal + /// + IServicePrincipal ServicePrincipal { get; } } }