首页 \ 问答 \ Sharepoint REST API和MVC AAD连接(Sharepoint REST api and MVC AAD connect)

Sharepoint REST API和MVC AAD连接(Sharepoint REST api and MVC AAD connect)

我的需求是通过C#中的服务器端执行此查询https://<tenant>.sharepoint.com/_api/search/query?querytext=%27contenttype:articles%27通过Sharepoint REST api。

我有来自MVC门户的Oauth2连接,所以我的目标是从连接中检索令牌并将其作为持票人令牌发送到共​​享点端点。

我的意思是这样的

  string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
  AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID));
  ClientCredential credential = new ClientCredential(clientId, appKey);
  AuthenticationResult result = await authContext.AcquireTokenSilentAsync("https://<tenant>.sharepoint.com/", credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

  HttpClient client = new HttpClient();
  HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://<tenant>.sharepoint.com/_api/search/query?querytext=%27contenttype:articles%27");
  request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
  HttpResponseMessage response = await client.SendAsync(request);

但显然,我无法检索令牌...

另一方面,我用ADv2和GraphServiceClient构建了一个运行良好的应用程序,但我不知道如何在图模型中转换查询(并且我没有任何管理员同意)。

所以,我有两种方法可以解决我的问题,我希望更好地使用Microsoft图形API的第二个选项,但是欢迎任何帮助。

谢谢。


My need is to execute this query https://<tenant>.sharepoint.com/_api/search/query?querytext=%27contenttype:articles%27 thru Sharepoint REST api from server side in C#.

I have Oauth2 connection from the MVC portal, so my goal is to retrieve token from connection and send it as bearer token to sharepoint endpoint.

I mean something like that

  string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
  AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID));
  ClientCredential credential = new ClientCredential(clientId, appKey);
  AuthenticationResult result = await authContext.AcquireTokenSilentAsync("https://<tenant>.sharepoint.com/", credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

  HttpClient client = new HttpClient();
  HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://<tenant>.sharepoint.com/_api/search/query?querytext=%27contenttype:articles%27");
  request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
  HttpResponseMessage response = await client.SendAsync(request);

but obviously, I can not retrieve the token...

On another side, I have built an app with ADv2 and GraphServiceClient that is working well, but I don't know how to translate the query in graph model (and I don't have any admin-consent).

So, I have 2 ways to resolve my issue, I'll like better use the 2nd option with microsoft graph api, but any help is welcome.

Thank you.


原文:https://stackoverflow.com/questions/48100279
更新时间:2022-05-20 13:05

最满意答案

从状态栏右下角选择项目/解决方案,它就像任何事情一样开始工作。

图片


Select Project /solution from status bar right bottom corner and it is started working like anything.

image

相关问答

更多
  • inline关键字表示函数定义应该插入任何使用它的代码。 大多数时候,这不会对函数的类型有任何影响。 然而,在极少数情况下,它可以导致具有更一般类型的函数,因为存在不能用.NET中的代码编译形式表达的约束,但是当函数内联时可以强制执行。 适用的主要情况是运营商的使用。 let add a b = a + b 将会有一个单一的推断类型(大概是int -> int -> int ,但是如果你有这个代码使用这个函数的代码,那么它可能是float -> float -> float )。 但是,通过内联标记这个函 ...
  • 您的代码是有效的F#扩展方法。 但这只适用于F#。 要在C#中使用扩展方法,必须使用“C#方式”。 那么,HtmlHelper代码: namespace FsCsMvc41WeApp.Helpers open System.Runtime.CompilerServices open System.Web; open System.Web.Mvc; [] type MyHelpers = [] static member sayHello(hel ...
  • 从状态栏右下角选择项目/解决方案,它就像任何事情一样开始工作。 Select Project /solution from status bar right bottom corner and it is started working like anything.
  • OmniSharp似乎加载了目前不支持.NET Core项目的VS 2017构建工具: https : //github.com/Microsoft/msbuild/issues/1697 。 尝试使用Web开发/跨平台工作负载安装VS 2017版本,或者在项目中创建包含以下内容的omnisharp.json文件: { "msbuild": { "msbuildextensionspath": "C:\\Program Files\\dotnet\\sdk\\1.0.4\\Sdks" ...
  • 您可以将函数序列化为JSON,然后反序列化它并稍后使用FSPickler执行该函数: open MBrace.FsPickler open MBrace.FsPickler.Json open System.IO open System.Text let serializer = JsonSerializer(indent = true) let utf8 = UTF8Encoding(false) let toJson (x: 'a) = use stream = new MemoryStre ...
  • 那么,这不是我的代码。 事实证明,当我使用链接示例中包含的确切ProvidedTypes-head.fs ,所有事情都像它应该的那样工作。 但是,当我使用不同的版本时,如FSharp.Data ,则它具有不正确的行为。 我不确定他们之间的差异是什么造成了这个问题。 我也不确定在哪里可以找到文件的“官方”版本,如果确实存在的话。 更新 :看起来像正式版本在这里 。 Well, it wasn't my code. It turns out that when I use the exact ProvidedT ...
  • 我们无法让OAuth工作,但受@ Helge的回答启发,我们能够以用户的方式伪造日志。 #r "System.Net.Http" open System open System.Collections.Generic open System.Net open System.Net.Http open System.Net.Http.Headers let toKVPairSeq l = Seq.map (fun (k, v) -> KeyValuePair(k, v)) l let handl ...
  • 根据配置文件中的示例,您应该在双引号内使用标准正则表达式。 不要使用/regex/replace/options的Perl样式。 config.json由OmniSharp服务器读取,该服务器是用C#编写的,所以如果你想用你的正则表达式做任何事情,请确保它们与C#兼容。 因此,例如,您的示例正则表达式将如下所示: "(Method)\s'\w+'\shas the same with\s'\w+'" Based on the examples in the config file, you should ...
  • 首先,安装运行时: //to install coreclr dnvm install latest -r coreclr -a coreclr-latest //to install the clr dnvm install latest -a mono-latest dnvm alias default [coreclr-latest | mono-latest] //depends on what you installed dnvm use default 让我知道ls -l ~/.dn ...
  • 从VSCode文档 :当omnisharp被加载时,右键单击其状态栏中的图标并选择更改项目,从那里您可以手动选择您的解决方案文件。 From VSCode documentation: When omnisharp is loaded right click its icon in the status bar and choose change projects, from there you can manually select your solution file.

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。