在不具有PublicClientApplicationBuilder和AcquireTokenInteractive的情况下,在MSAL中获得EWS的委托权限

问题描述 投票:0回答:1

在EWS OAuth流程中,我们可以通过以下方式获得委托权限:

var pcaOptions = new PublicClientApplicationOptions
{
    ClientId = ConfigurationManager.AppSettings["appId"],
    TenantId = ConfigurationManager.AppSettings["tenantId"]
};

var pca = PublicClientApplicationBuilder
    .CreateWithApplicationOptions(pcaOptions).Build();

// The permission scope required for EWS access
var ewsScopes = new string[] { "https://outlook.office.com/EWS.AccessAsUser.All" };

// Make the interactive token request
var authResult = await pca.AcquireTokenInteractive(ewsScopes).ExecuteAsync();

以上代码打开用于输入用户名/密码的对话框。

有什么方法可以通过在代码本身中提供凭据来绕过对话框并请求令牌,但仅具有委派权限

c# azure office365 exchangewebservices msal
1个回答
0
投票

是的,您所说的是ROPC https://docs.microsoft.com/en-us/azure/active-directory//develop/v2-oauth-ropc。通常不建议以这种方式使用凭据,因为直接处理凭据周围存在信任问题。您需要确保的一件事是在您的应用程序注册中,您具有

作为公共客户端处理应用程序。

在身份验证标签中选择(位于最底部)

要查看代码,请查看https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Username-Password-Authentication例如

NetworkCredential Credentials =  new NetworkCredential(UserName,Password); 
pca.AcquireTokenByUsernamePassword(ewsScopes,Credentials.UserName, Credentials.SecurePassword).ExecuteAsync();

如果您寻求更安全的方法,请考虑使用托管身份https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview

© www.soinside.com 2019 - 2024. All rights reserved.