我在我的项目中使用了 Microsoft Graph SDK 来调用图形 API,为此我需要使用 GraphServiceClient。要使用 GraphServiceClient,我必须添加一些辅助类,其中 SDKHelper 是具有 GetAuthenticatedClient() 方法的静态类。由于被测方法与静态的 SDKHelper 紧密耦合,因此我创建了一个服务类并注入了依赖项。
下面是控制器和方法,
public class MyController
{
private IMyServices _iMyServices { get; set; }
public UserController(IMyServices iMyServices)
{
_iMyServices = iMyServices;
}
public async Task<HttpResponseMessage> GetGroupMembers([FromUri]string groupID)
{
GraphServiceClient graphClient = _iMyServices.GetAuthenticatedClient();
IGroupMembersCollectionWithReferencesPage groupMembers = await _iMyServices.GetGroupMembersCollectionWithReferencePage(graphClient, groupID);
return this.Request.CreateResponse(HttpStatusCode.OK, groupMembers, "application/json");
}
}
Run Code Online (Sandbox Code Playgroud)
服务类,
public class MyServices : IMyServices
{
public GraphServiceClient GetAuthenticatedClient()
{
GraphServiceClient graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
string accessToken …Run Code Online (Sandbox Code Playgroud) 我在 Visual Studio 2015 Professional 中创建了新的 asp.net mvc 5 项目,并且我在我的内容安全策略布局中添加了元标记作为 -
<meta http-equiv="content-security-policy"
content="default-src 'none'; script-src 'self';
connect-src 'self'; img-src 'self'; style-src 'self';" />
Run Code Online (Sandbox Code Playgroud)
现在,当我运行我的应用程序时,我在 chrome 浏览器控制台中收到以下错误 -
拒绝应用内联样式,因为它违反了以下内容安全策略指令:“style-src 'self'”。启用内联执行需要“unsafe-inline”关键字、哈希(“sha256-CwE3Bg0VYQOIdNAkbB/Btdkhul49qZuwgNCMPgNY5zw=')或随机数(“nonce-...”)。Modernizr-2.6.2.js:157
Modernizr-2.6.2.js:157 有 6 个错误,其中一个与脚本有关,即拒绝加载脚本 localhost
我认为我的项目中没有任何内联样式,那么为什么 CSP 拒绝应用错误?
在阅读Microsoft文档后,我确定可以使用OData查询参数过滤组成员,因为https://developer.microsoft.com/zh-cn/graph/docs/api-reference/v1.0/api/group_list_members
请求GET URL- https: //graph.microsoft.com/v1.0/groups/ {groupId} / members?filter = startswith(givenname,'V')
在上面的URL中,从https://graph.microsoft.com/v1.0/groups使用了groupId
但是,当我尝试使用工作帐户登录名使用Graph Explorer(https://developer.microsoft.com/en-us/graph/graph-explorer)获取结果时,它不起作用。
我也尝试在SDK中使用它(我已经使用Microsoft graph API SDK在我的代码中实现了graph API),但仍然遇到相同的错误。
并给出以下错误-
{“错误”:{“代码”:“ Request_UnsupportedQuery”,“消息”:“当前不支持对参考属性查询的指定过滤器。”,“ innerError”:{“ request-id”:“ 96f3ffef-56f5- 42e3-82f2-64813106b729“,” date“:” 2018-02-13T10:59:39“}}}
这是因为“成员”不是资源类型吗?所以它没有属性,所以我们不能过滤此结果?
如果是这样,那么还有其他方法可以获取已过滤的组成员吗?
在Github上也发布了问题-https: //github.com/microsoftgraph/microsoft-graph-docs/issues/2239