Xero PHP API Error: "You are not permitted to access this resource"
Xero PHP API Error: "You are not permitted to access this resource"
我有 Xero API 设置和 OAuth 流程。我已将“Demo Company UK”链接为租户(组织),并已授予我的用户顾问 • 联系银行账户管理员、薪资管理员 • 费用(管理员)权限(似乎是最高级别)位于此处:https://go.xero.com/Settings/Users 但我仍然收到以下错误。 “您无权访问此资源”我已经添加了所有应该涵盖请求的 scopes 并且具有有效的 access token 但仍然没有不错。
'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".
}
有人遇到过这个问题吗?
问题是我在创建 new XeroApp
class 实例时传递了 id_token
。我没有看到存储在数据库(非常大)中的 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
我会保持此线程打开,以防它能帮助到任何人。
Nice save Nick - 是的,id_token
可用于 “使用 Xero 注册” 之类的事情,如果您的业务运营是核心业务,这将是一个巨大的优势财务数据。
https://developer.xero.com/documentation/oauth2/sign-up
它本质上使您能够在您的系统中配置帐户(使用解码的 ID 令牌名称/电子邮件)并在单个流程中同步他们的 Xero 数据。我们看到合作伙伴因此显着减少了新注册的流失。
综上所述,有效的 access_token
和 tenant_id
是进行授权 API 调用所需的东西。
我有 Xero API 设置和 OAuth 流程。我已将“Demo Company UK”链接为租户(组织),并已授予我的用户顾问 • 联系银行账户管理员、薪资管理员 • 费用(管理员)权限(似乎是最高级别)位于此处:https://go.xero.com/Settings/Users 但我仍然收到以下错误。 “您无权访问此资源”我已经添加了所有应该涵盖请求的 scopes 并且具有有效的 access token 但仍然没有不错。
'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".
}
有人遇到过这个问题吗?
问题是我在创建 new XeroApp
class 实例时传递了 id_token
。我没有看到存储在数据库(非常大)中的 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
我会保持此线程打开,以防它能帮助到任何人。
Nice save Nick - 是的,id_token
可用于 “使用 Xero 注册” 之类的事情,如果您的业务运营是核心业务,这将是一个巨大的优势财务数据。
https://developer.xero.com/documentation/oauth2/sign-up
它本质上使您能够在您的系统中配置帐户(使用解码的 ID 令牌名称/电子邮件)并在单个流程中同步他们的 Xero 数据。我们看到合作伙伴因此显着减少了新注册的流失。
综上所述,有效的 access_token
和 tenant_id
是进行授权 API 调用所需的东西。