问题描述
我有Xero API设置和OAuth流程。我已将“ Demo Company UK”作为租户(组织)进行了链接,并向我的用户授予了顾问•银行帐户管理员,薪资管理员•费用(管理员)权限(似乎是最高级别)位于以下位置:{ {3}},但仍然出现以下错误。 “您无权访问此资源”,我添加了所有范围,这些范围应涵盖请求并具有有效的访问令牌,但效果仍然不佳。
'client_id' => env('XERO_CLIENT_ID'),'client_secret' => env('XERO_CLIENT_SECRET'),'redirect_uri' => env('XERO_REDIRECT_URI'),'scope' => 'openid email profile offline_access accounting.transactions accounting.contacts accounting.contacts.read accounting.reports.read',
示例函数进行基本调用以使用户进入帐户。与Xero的连接很好,但是一旦我尝试请求任何数据,就会引发相同的错误。
public function testXero() {
$xeroAccesstoken = GlobalSetting::where('name','=','xero_access_token')->first();
$xeroTenantOrganisation = GlobalSetting::where('name','xero_tenant_organisation_id')->first();
$xero = new XeroApp(
new Accesstoken(
array(
'access_token' => json_decode($xeroAccesstoken->value)->id_token
)
),$xeroTenantOrganisation->value
);
//dd( $xero ); //we have a succesfull connection here...
# Retrieve all contacts
$contacts = $xero->contacts()->get();
dd($contacts); //error "You are not permitted to access this resource".
}
有人遇到过这个问题吗?
解决方法
问题是我在创建id_token
类实例时传递了new XeroApp
。我看不到存储在数据库中的JSON对象中的所有其他对象(非常大)。有一个实际的access_token
与我在通话中所做的其他一些有用的信息一起存储。
$xero = new XeroApp(
new AccessToken(
array(
'access_token' => json_decode($xeroAccessToken->value)->access_token,'refresh_token' => json_decode($xeroAccessToken->value)->refresh_token,'expires' => json_decode($xeroAccessToken->value)->expires,)
),$xeroTenantOrganisation->value
);
$contacts = $xero->contacts;
dd($contacts);//RESULTS!!! YES
我将保持此线程开放,以防万一它帮助任何人。
,保存得很好,尼克-是的,id_token
可用于“使用Xero注册” 之类的功能,如果您的业务运营是财务数据的核心,则这将是一个巨大的优势。 / p>
https://developer.xero.com/documentation/oauth2/sign-up
从本质上讲,它使您可以在系统中配置帐户(使用解码的ID令牌名称/电子邮件)并在单个流程中同步其Xero数据。我们已经看到合作伙伴因此大大减少了新注册的失败。
总而言之,有效的access_token
和tenant_id
是进行授权的API调用所必需的。