python web api authorization_python – 使用MS Dynamics CRM 2016的REST Web API在线进行身份验证...

我正在尝试访问新的REST API,以构建服务器到服务器接口,以将CRM与其他应用程序(如网店等)集成.

我尝试了从Azure AD获取访问令牌的两种方法:

客户凭证

import adal

token_response = adal.acquire_token_with_client_credentials(

'https://login.microsoftonline.com/abcdefgh-1234-5678-a1b1-morerandomstuff',

client_id,

secret

)

和用户/密码

import adal

token_response = adal.acquire_token_with_username_password(

'https://login.microsoftonline.com/abcdefgh-1234-5678-a1b1-morerandomstuff',

'interface@crm.my_domain.com',

'my_password'

)

在这两种情况下,token_response都会获得一个token-object,包含accessToken,refreshToken,expiresIn等.所以我认为到目前为止还没有错误.

然后我尝试向Web API发出一个简单的请求:

headers = {'Authorization': '%s %s' % (token_response.get('tokenType'),

token_response.get('accessToken'))}

r = requests.get('https://domain.api.crm4.dynamics.com/api/data/v8.0/Product',

headers=headers)

这总是返回HTTP 401 – 未授权:访问被拒绝.

('WWW-Authenticate', 'Bearer error=invalid_token,

error_description=Error during token validation!,

authorization_uri=https://login.windows.net/eabcdefgh-1234-5678-a1b1-morerandomstuff/oauth2/authorize,

resource_id=https://domain.api.crm4.dynamics.com/')

尝试发出请求的用户具有Office-365-Administrator权限,并且在CRM中具有所有管理员角色和管理员角色.根据我的口味,这甚至有点多,但我在某处读到,用户必须拥有office-365管理员权限.

在Azure AD中,配置了一个应用程序,该应用程序具有对CRM的“委派权限”(“作为组织用户访问CRM Online”).

我在这里错过了什么?或者我的REST-get-request错了?

新API的Microsoft文档几乎不存在 – 每当您单击某个链接时,您将获得旧API(组织API等)的文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值