首页 > 解决方案 > Sharepoint REST api - 领域不是当前服务命名空间错误 50169 的配置领域

问题描述

我在尝试从 Sharepoint REST api 获取身份验证令牌时遇到此错误。我的 SP 是基于云的,我正在使用 Postman 来测试请求,因为之前的尝试同样陷入了死胡同,因为 Msoft 来回进行大量故障排除导致无处可去。无论如何,我有以下错误,我想知道是否任何人都可以帮助我弄清楚它是什么或如何解决这个问题。

error_description: "AADSTS50169: The realm 'realm' is not a configured realm of the current service namespace"
error_codes : 50169

我跟着这个教程

谢谢!

编辑:我经历并重新开始,这个 tut 似乎正在工作我想我可能错过了一步(我的猜测是我在创建应用程序时没有使用 xml 正确配置应用程序权限)

标签: azureazure-active-directorysharepoint-online

解决方案


要通过 Postman 在线授权 SharePoint 并使用 REST API,这里有一个解决方案供您参考:

第一:获取安全Token

通过 Http Post 方法访问 [ https://login.microsoftonline.com/extSTS.srf] 。http请求的内容如下。

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"  
  xmlns:a="http://www.w3.org/2005/08/addressing"  
  xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity- 
utility-1.0.xsd">  
<s:Header>  
<a:Action 
s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>  
<a:ReplyTo>  
  <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>  
</a:ReplyTo>  
<a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>  
<o:Security s:mustUnderstand="1"  
   xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">  
  <o:UsernameToken>  
    <o:Username>[username]</o:Username>  
    <o:Password>[password]</o:Password>  
  </o:UsernameToken>  
</o:Security>  
</s:Header>  
<s:Body>  
<t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">  
  <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">  
    <a:EndpointReference>  
      <a:Address>[endpoint]</a:Address>  
    </a:EndpointReference>  
  </wsp:AppliesTo>  
  <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>  
  <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>  
  <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>  
</t:RequestSecurityToken>  
</s:Body>  
</s:Envelope>  

Postman 中的演示截图:

在此处输入图像描述

并且响应内容将包含一个安全令牌,如下所示,我们可以使用这个安全令牌来获取 SharePoint 的访问令牌。

在此处输入图像描述

二:获取Access Token

在这里,我将向您展示如何使用安全令牌和 SharePoint Rest API 在线获取 SharePoint 的访问令牌。

通过 http Post 方法访问 [ https://yourdomain.sharepoint.com/_forms/default.aspx?wa=wsignin1.0] 。请求的内容是我们上面得到的安全令牌,如下所示。 在此处输入图像描述

响应如下:

在此处输入图像描述

我们可以看到响应头中有两个cookie,rtFa和FedAuth,这两个cookie需要在后续请求中添加到请求中。

第三:获取请求摘要

使用我们上面得到的两个 cookie 通过 http Post 方法访问 [ https://yourdomain.sharepoint.com/_api/contextinfo] 。

在此处输入图像描述

响应如下:

在此处输入图像描述

这是我们想要的最终代币!

然后我们就可以使用SharePoint的REST API了,我们只需要加上这个token和前面的两个cookie,如下图所示。

在此处输入图像描述


推荐阅读