outlook 服务器身份验证,Outlook 加载项中的身份验证选项

Outlook 加载项中的身份验证选项

06/22/2021

本文内容

Outlook 加载项可以访问 Internet 上任意位置的信息,无论是托管加载项的服务器、内部网络,还是云中的其他位置。 如果相应信息受保护,加载项需要能够验证用户身份。 Outlook 加载项 根据特定场景提供了多种不同的身份验证方法。

单一登录访问令牌

单一登录访问令牌为你的加载项提供了进行身份验证和获取访问令牌以调用 Microsoft Graph API 的无缝方法。 由于不需要用户输入其凭据,此功能可以减少摩擦。

备注

目前,Word、Excel、Outlook 和 PowerPoint 支持单一登录 API。 若要详细了解目前支持单一登录 API 的平台,请参阅 IdentityAPI 要求集。

如果使用的是 Outlook 加载项,请务必为 Microsoft 365 租赁启用新式验证。 若要了解如何执行此操作,请参阅 Exchange Online: How to enable your tenant for modern authentication(如何为租户启用新式体验)。

如果加载项符合以下情况,请考虑使用 SSO 访问令牌:

主要由 Microsoft 365 用户使用

需要访问以下服务:

作为 Microsoft Graph 的一部分公开的 Microsoft 服务

你控制的非 Microsoft 服务

SSO 身份验证方法使用 Azure Active Directory 提供的 OAuth2 代表流。 它要求加载项在应用程序注册门户中进行注册并在其清单中指定任何所需的 Microsoft Graph 作用域。

借助此方法,加载项可以获取作用域为你的服务器后端 API 的访问令牌。 加载项将此令牌用作 Authorization 标头中的持有者令牌,来对 API 回调进行身份验证。 此时,服务器可以:

完成“代表”流来获取作用域为 Microsoft Graph API 的访问令牌

使用令牌中的标识信息创建用户标识并对自己的后端服务进行身份验证

有关在 Outlook 加载项中使用 SSO 令牌的详细信息,请参阅在 Outlook 加载项中使用单一登录令牌对用户进行身份验证。

有关使用 SSO 令牌的加载项示例,请参阅 Outlook 加载项 SSO。

Exchange 用户标识令牌

Exchange 用户标识令牌为加载项提供了一种创建用户标识的方法。 通过验证用户标识,可以对后端系统执行一次性身份验证,然后接受用户标识令牌,来作为对未来请求的授权。 使用 Exchange 用户标识令牌:

当加载项主要由 Exchange 本地用户使用时。

当加载项需要访问你控制的非 Microsoft 服务时。

当加载项在不支持 SSO 的 Office 版本上运行时,要回退身份验证。

通过 OAuth2 流获取的访问令牌

加载项也可以访问支持 OAuth2 进行授权的第三方服务。 如果你的加载项符合以下情况,请考虑使用 OAuth2 令牌:

需要访问不受你控制的第三方服务

使用此方法,加载项会提示用户通过使用 displayDialogAsync 方法初始化 OAuth2 流或使用 office-js-helpers 库 转到 OAuth2 隐式流来登录到服务。

回调令牌

借助回调令牌,可以使用 Exchange Web 服务 (EWS) 或 Outlook REST API 从服务器后端访问用户邮箱。 如果你的加载项符合以下情况,请考虑使用回调令牌:

需要从服务器后端访问用户邮箱。

加载项使用 getCallbackTokenAsync方法之一获取回调令牌。 访问权限级别由加载项清单中指定的权限控制。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在JavaMail中使用Outlook的MFA验证需要使用Microsoft Graph API进行身份验证。您需要在Microsoft Azure门户中创建一个应用程序并授权该应用程序访问Outlook邮件。然后,您需要使用Java程序获取访问令牌并在JavaMail中使用该令牌进行身份验证。 以下是一个使用Outlook的JavaMail MFA验证示例: ```java import java.net.URI; import java.util.Collections; import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import com.microsoft.aad.msal4j.*; import com.microsoft.graph.authentication.IAuthenticationProvider; import com.microsoft.graph.http.IHttpRequest; import com.microsoft.graph.models.extensions.IGraphServiceClient; import com.microsoft.graph.requests.extensions.GraphServiceClient; public class JavaMailOutlookMFAExample { public static void main(String[] args) throws Exception { String clientId = "your_client_id"; String clientSecret = "your_client_secret"; String tenantId = "your_tenant_id"; String username = "your_email_address"; String mfaToken = "your_mfa_token"; // MFA token generated by your authenticator app // Initialize MSAL4J ConfidentialClientApplication IConfidentialClientApplication app = ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.createFromSecret(clientSecret)) .authority("https://login.microsoftonline.com/" + tenantId) .build(); // Acquire an access token for the Microsoft Graph API String[] scopes = { "https://graph.microsoft.com/.default" }; IAuthenticationResult result = app.acquireToken(ClientCredentialParameters.builder(Collections.singleton(scopes)).build()).get(); String accessToken = result.accessToken(); // Create an IAuthenticationProvider for Microsoft Graph API IAuthenticationProvider authProvider = new IAuthenticationProvider() { @Override public void authenticateRequest(IHttpRequest request) { request.addHeader("Authorization", "Bearer " + accessToken); } }; // Create an IGraphServiceClient for Microsoft Graph API IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient(); // Use Microsoft Graph API to get the user's email address String userEmailAddress = graphClient.me().get().mail().toString(); // Set JavaMail properties for Outlook Properties props = new Properties(); props.put("mail.store.protocol", "https"); props.put("mail.smtp.host", "smtp.office365.com"); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); // Create a JavaMail Session Session session = Session.getDefaultInstance(props); // Enable debugging output session.setDebug(true); // Create a JavaMail Store for Outlook Store store = session.getStore("https"); store.connect("outlook.office365.com", userEmailAddress, accessToken + mfaToken); // Create a JavaMail Folder for the Inbox Folder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_ONLY); // Print the number of messages in the Inbox System.out.println("Number of messages in Inbox: " + inbox.getMessageCount()); // Close the JavaMail Folder and Store inbox.close(false); store.close(); System.out.println("Done."); } } ``` 在此示例中,您需要使用您的Azure应用程序的客户端ID、客户端密钥和租户ID替换示例代码中的`clientId`、`clientSecret`和`tenantId`变量。在运行示例程序之前,您需要先使用MSAL4J库获取访问令牌,然后使用该令牌进行Outlook身份验证。此外,您需要在JavaMail的配置中设置`mail.store.protocol`属性为`https`,并将`mail.smtp.host`和`mail.smtp.port`属性设置为`smtp.office365.com`和`587`。 请注意,Outlook的MFA验证可能需要不同的配置参数。因此,建议您查阅Microsoft Graph API文档以了解如何在JavaMail中使用Outlook的MFA验证。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值