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
最满意答案
从状态栏右下角选择项目/解决方案,它就像任何事情一样开始工作。
Select Project /solution from status bar right bottom corner and it is started working like anything.
相关问答
更多-
在F#中使用`inline`(Use of `inline` in F#)[2023-08-22]
inline关键字表示函数定义应该插入任何使用它的代码。 大多数时候,这不会对函数的类型有任何影响。 然而,在极少数情况下,它可以导致具有更一般类型的函数,因为存在不能用.NET中的代码编译形式表达的约束,但是当函数内联时可以强制执行。 适用的主要情况是运营商的使用。 let add a b = a + b 将会有一个单一的推断类型(大概是int -> int -> int ,但是如果你有这个代码使用这个函数的代码,那么它可能是float -> float -> float )。 但是,通过内联标记这个函 ... -
HtmlHelper MVC 5 F#(HtmlHelper MVC 5 F#)[2023-02-14]
您的代码是有效的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" ...
-
序列化F#函数(Serializing an F# function)[2023-06-10]
您可以将函数序列化为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 ...
-
VS Code,OmniSharp:Project有这些未解决的参考:(VS Code, OmniSharp: Project has these unresolved references:)[2022-07-07]
首先,安装运行时: //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.