使用带有硬编码用户名和密码的 Office Outlook API
Using Office Outlook API with hard-code user name and password
我正在尝试构建一个 (C#) 网络应用程序,允许客户与我进行约会。
我希望网络应用程序能够读取条目并将条目添加到我的 Outlook 日历中。
许多用户会使用网络应用程序,但网络应用程序只能访问一个 outlook 日历——我的。
我能够开始工作的所有示例都涉及 Web 应用程序用户交互式身份验证 - 但我的用户不会知道我的密码。
我想在网络应用程序中硬编码我的 username/email 地址和密码。
尝试获取令牌时出现错误:
Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:
AADSTS65001: The user or administrator has not consented to use the application.
Send an interactive authorization request for this user and resource.
我不是租户的管理员。有没有什么办法可以让我在没有管理员参与的情况下工作?
使用某种证书而不是用户名和密码作为用户凭据会有帮助吗?
我的代码(目前在一个简单的 C# 控制台应用程序中)如下:
UserCredential uc = new UserCredential(MyUsername, MyPassword);
var AuthContext = new AuthenticationContext("https://login.windows.net/Common");
// this doesn't work unless an unexpired token already exists
ar = AuthContext.AcquireToken("https://outlook.office365.com/", MyClientId, uc);
// this does work, but requires the app user to know the password
ar = AuthContext.AcquireToken("https://outlook.office365.com/", MyClientId, new Uri(MyReturnURI));
要启用使用用户名和密码直接请求令牌,我们需要同意使用该应用程序。
我们可以使用 OAuth 2.0 授权代码授予流程 来授予用户同意。以下是使用 ADAL 身份验证库 (3.13.1.846) 获取委托令牌的示例:
static string authority= "https://login.microsoftonline.com/common";
public static string GetDeligateToken(string resource, string clientId,string redirectURL)
{
AuthenticationContext authContext = new AuthenticationContext(authority);
AuthenticationResult authResult= authContext.AcquireTokenAsync(resource, clientId,new Uri(redirectURL), new PlatformParameters(PromptBehavior.Auto)).Result;
return authResult.AccessToken;
}
我们同意该应用程序后,现在我们可以使用您post中的代码来获取令牌。
我正在尝试构建一个 (C#) 网络应用程序,允许客户与我进行约会。 我希望网络应用程序能够读取条目并将条目添加到我的 Outlook 日历中。 许多用户会使用网络应用程序,但网络应用程序只能访问一个 outlook 日历——我的。 我能够开始工作的所有示例都涉及 Web 应用程序用户交互式身份验证 - 但我的用户不会知道我的密码。 我想在网络应用程序中硬编码我的 username/email 地址和密码。
尝试获取令牌时出现错误:
Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:
AADSTS65001: The user or administrator has not consented to use the application.
Send an interactive authorization request for this user and resource.
我不是租户的管理员。有没有什么办法可以让我在没有管理员参与的情况下工作? 使用某种证书而不是用户名和密码作为用户凭据会有帮助吗?
我的代码(目前在一个简单的 C# 控制台应用程序中)如下:
UserCredential uc = new UserCredential(MyUsername, MyPassword);
var AuthContext = new AuthenticationContext("https://login.windows.net/Common");
// this doesn't work unless an unexpired token already exists
ar = AuthContext.AcquireToken("https://outlook.office365.com/", MyClientId, uc);
// this does work, but requires the app user to know the password
ar = AuthContext.AcquireToken("https://outlook.office365.com/", MyClientId, new Uri(MyReturnURI));
要启用使用用户名和密码直接请求令牌,我们需要同意使用该应用程序。
我们可以使用 OAuth 2.0 授权代码授予流程 来授予用户同意。以下是使用 ADAL 身份验证库 (3.13.1.846) 获取委托令牌的示例:
static string authority= "https://login.microsoftonline.com/common";
public static string GetDeligateToken(string resource, string clientId,string redirectURL)
{
AuthenticationContext authContext = new AuthenticationContext(authority);
AuthenticationResult authResult= authContext.AcquireTokenAsync(resource, clientId,new Uri(redirectURL), new PlatformParameters(PromptBehavior.Auto)).Result;
return authResult.AccessToken;
}
我们同意该应用程序后,现在我们可以使用您post中的代码来获取令牌。