Microsoft graph authorization code flow - get authorization code from web app programmatically

不羁的心 提交于 2021-02-11 14:59:47

问题


I have created web app to CreateOrGet, Delete, Update onlinemeeting using Microsoft Graph API in C#.

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.

Is there any way to do this through code in C#?


回答1:


You don't need to handle the "code" and "access token" by your self.

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);


来源:https://stackoverflow.com/questions/63806580/microsoft-graph-authorization-code-flow-get-authorization-code-from-web-app-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!