Microsoft图形授权码流程-以编程方式从Web应用程序获取授权码 [英] Microsoft graph authorization code flow - get authorization code from web app programmatically
问题描述
我已经使用C#中的Microsoft Graph API创建了用于创建或获取,删除,更新在线会议的Web应用程序.
I have created web app to CreateOrGet, Delete, Update onlinemeeting using Microsoft Graph API in C#.
要获取每个链接的授权代码代表某位用户访问用户.当HttpClient调用AuthCodeGeneration的api时,它返回一个webview并返回响应,该响应包含浏览器中的Authcode.我必须手动复制它才能使用Microsoft Graph API执行CreateOrGet,删除,更新在线会议.
To get authorization code as per link Get access on behalf of a user. It returns a webview as HttpClient calls api for AuthCodeGeneration and returns the response, which contains Authcode in browser. I have to manually copy it to execute CreateOrGet, Delete, Update onlinemeeting using Microsoft Graph API.
有什么办法可以通过C#中的代码来做到这一点?
Is there any way to do this through code in C#?
推荐答案
您无需处理"code"和访问令牌"靠你自己.
You don't need to handle the "code" and "access token" by your self.
安装Microsoft Graph .NET SDK 并实施授权代码提供者以获取 authProvider
.使用 authProvider
生成 graphClient
.
Install Microsoft Graph .NET SDK and implement Authorization code provider to get the authProvider
. Use the authProvider
to generate the graphClient
.
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithRedirectUri(redirectUri)
.WithClientSecret(clientSecret)
.Build();
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(confidentialClientApplication, scopes);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var onlineMeeting = new OnlineMeeting
{
StartDateTime = DateTimeOffset.Parse("2019-07-12T21:30:34.2444915+00:00"),
EndDateTime = DateTimeOffset.Parse("2019-07-12T22:00:34.2464912+00:00"),
Subject = "User Token Meeting"
};
await graphClient.Me.OnlineMeetings
.Request()
.AddAsync(onlineMeeting);
这篇关于Microsoft图形授权码流程-以编程方式从Web应用程序获取授权码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!