通过.Net代码使用REST API进行模拟 [英] Impersonation using REST API through .Net code

查看:56
本文介绍了通过.Net代码使用REST API进行模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Experts,

Hi Experts,

我正在开发一个应用程序,它使用SharePoint加载项在SharePoint中创建/上载/共享文件。我正在使用Rest API做这一切。

I am developing an application, that uses SharePoint Add-ins to Create/Upload/Share files in SharePoint. I am doing all this using the Rest API.

我的问题是,将来我会要求用户登录我的应用程序并显示列表/文件,我仍然会继续使用SharePoint加载项创建/上载/共享文件。但是,我想根据登录用户
冒充请求,并根据他拥有的权限向他显示允许给他的文件/列表。

My question is, in future I'll ask the user to login into my application and show the lists/files, and I would still continue using the SharePoint Add-Ins to Create/Upload/Share files. But, I'd want to impersonate the request based on the logged-in user and show him the files/lists that are allowed to him based on the permissions that he has.

对此的任何指导都会非常感激。

Any guidance on this would really be appreciated.

谢谢!

推荐答案

您可以在Rest API中查看特定用户帐户的列表用户权限:

You can check the list user permission for a specific user account like this in Rest API:

function getListUserEffectivePermissions(webUrl,listTitle, accountName) 
{
    var endpointUrl = webUrl +  "/_api/web/lists/getbytitle('" + listTitle + "')/getusereffectivepermissions(@u)?@u='" + encodeURIComponent(accountName) + "'";
    return


.getJSON(endpointUrl);
}

函数parseBasePermissions(value)
{
var permissions = new SP.BasePermissions();
permissions.initPropertiesFromJson(value);
var permLevels = [];
for(SP.PermissionKind.prototype中的var permLevelName){
if(SP.PermissionKind.hasOwnProperty(permLevelName)){
var permLevel = SP.PermissionKind.parse(permLevelName);
if(permissions.has(permLevel)){
permLevels.push(permLevelName);
}
}
}
返回permLevels;
}
.getJSON(endpointUrl); } function parseBasePermissions(value) { var permissions = new SP.BasePermissions(); permissions.initPropertiesFromJson(value); var permLevels = []; for(var permLevelName in SP.PermissionKind.prototype) { if (SP.PermissionKind.hasOwnProperty(permLevelName)) { var permLevel = SP.PermissionKind.parse(permLevelName); if(permissions.has(permLevel)){ permLevels.push(permLevelName); } } } return permLevels; }

用法:

var webUrl = _spPageContextInfo.webAbsoluteUrl;  
getListUserEffectivePermissions(webUrl,'Documents','i:0#.f|membership|jdoe@tenant.onmicrosoft.com')
        .done(function(data){
            var roles = parseBasePermissions(data);
            console.log(roles); 
        });
		




结果:

["emptyMask", "viewListItems", "addListItems", "editListItems", "deleteListItems", "openItems", "viewVersions", "deleteVersions", "managePersonalViews", "viewFormPages", "open", "viewPages", "createSSCSite", "browseDirectories", "browseUserInfo", "addDelPrivateWebParts", "updatePersonalWebParts", "useClientIntegration", "useRemoteAPIs", "createAlerts", "editMyUserInfo"]

如果想通过.NET代码模拟Rest API,可以使用HttpClient Class来实现:

And if want to impersonate Rest API through .NET code, you could use HttpClient Class to achieve:

在C#托管代码中使用SharePoint 2013 REST API

谢谢

最好的问候


这篇关于通过.Net代码使用REST API进行模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆