【问题标题】:External REST Service Authentication from SharePoint OnlineSharePoint Online 的外部 REST 服务身份验证
【发布时间】:2016-05-30 14:50:48
【问题描述】:

经常使用 SharePoint Online 创建复杂的业务应用程序,我需要将业务逻辑外部化到外部服务,以便使用 .net 代码和第三方程序集。

就我而言,我正在开发一个由 Azure 网站托管的 Rest Service。

Here my architecture

我的问题是:

我能否从 SharePoint 获取包含当前用户信息的访问令牌,将其传递给外部 Rest Service,然后重新使用它以使用当前用户凭据将用户返回并验证到 SharePoint?

从两个 JavaScript 代码和 2013 工作流调用此服务

你能给我有关它的文档吗?

谢谢,

塞尔吉奥

【问题讨论】:

    标签: azure authentication sharepoint office365 adal


    【解决方案1】:

    来自 SharePoint Online 的外部 REST 服务身份验证...从 2013 工作流的两个 JavaScript 代码调用此服务

    SharePoint Online 默认受 Azure AD 保护。根据描述,有两种认证场景。首先是您想在联机登录 SharePoint 后调用自定义 REST 服务而不进行身份验证。 二是可以通过SharePoint在线用户的凭证获取token交换来调用REST服务。

    在第一个场景中,我们可以集成 Open Connect ID 来验证 REST 服务。而在第二种情况下,我们可以使用 OAuth 2.0 来集成 Azure AD。

    以下是演示解决方案的主要步骤:

    1. 在 Azure AD 上注册 Web 应用

    2. 创建 MVC 和 Web API 项目

    3. 添加以下代码以在中使用 Open connect ID 和 OAuth 2.0 ConfigureAuth(IAppBuilder app) 方法(Startup.Auth.cs)

      app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
      
      app.UseCookieAuthentication(new CookieAuthenticationOptions());
      
      app.UseOpenIdConnectAuthentication(
          new OpenIdConnectAuthenticationOptions
          {
              ClientId = "5efa8abc-13dc-4681-83f5-c6fde07116ac",
              Authority = "https://login.windows.net/yourtenant.onmicrosoft.com",
              PostLogoutRedirectUri = "http://localhost:24865/",
          });
      
          app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
          {
                  Audience = "https://yourtenant-my.sharepoint.com/",
                  Tenant = "yourtenant.onmicrosoft.com"
          });
      

    有关 Azure AD 受保护资源的更多详细信息,您可以参考以下链接:

    Web App Sign In & Sign Out with Azure AD

    Protect a Web API using Bearer tokens from Azure AD

    【讨论】:

    • 嗨。感谢您的回复。我的请求没有让我登录我的 WebApi 服务,匿名身份验证适合我。我想使用调用我的服务的用户的凭据在 SharePoint 网站中验证我的服务(CSOM 或 rest)。有可能吗?如何从 SharePoint 获取 STSToken 以在我的 Web api 服务中重用?非常感谢,塞尔吉奥
    • 您可以通过添加代码“app.UseWindowsAzureActiveDirectoryBearerAuthentication”重用来自 SharePoint 的令牌。您可以转到here 以检索令牌中的受众,并将其替换为上面代码示例中的租户。而且我还上传了MVCProtecedByAzureAD项目进行测试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 2017-10-16
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    相关资源
    最近更新 更多