创建 OAuth 凭据
请求参数
参数 | 类型 | 说明 | 必需的 |
---|---|---|---|
action | string | “CreateOAuthCredential” | Required |
grantType | string | ‘authorization_code’ 或 ‘single_sign_on’ 之一 | Required |
scope | string | tbloauthserver_scopes 中有效范围的空格分隔列表 | Required |
name | string | 为 authorization_code $grantType 提供 oAuth 凭据的名称 | Optional |
serviceId | int | single_sign_on $grantType 的服务 ID | Optional |
description | string | OAuth 凭证的说明 | Optional |
logoUri | string | 此应用程序的徽标图像文件的相对于基本 WHMCS 客户区目录的 URL 或路径。 | Optional |
redirectUri | string | 授权的重定向 URI | Optional |
响应参数
参数 | 类型 | 说明 |
---|---|---|
result | string | 操作结果:成功或错误 |
credentialId | int | 新创建的oauth凭证的ID |
clientIdentifier | string | 随机生成的 oauth 客户端标识符 |
clientSecret | string | 身份验证凭据的随机生成的秘密 |
示例请求 (CURL)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'CreateOAuthCredential',
// See https://developers.whmcs.com/api/authentication
'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
'password' => 'SECRET_OR_HASHED_PASSWORD',
'grantType' => 'single_sign_on',
'scope' => 'clientarea:sso clientarea:billing_info clientarea:announcements',
'serviceId' => '1',
'description' => 'Billing and Announcements SSO',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
示例请求(本地 API)
$command = 'CreateOAuthCredential';
$postData = array(
'grantType' => 'single_sign_on',
'scope' => 'clientarea:sso clientarea:billing_info clientarea:announcements',
'serviceId' => '1',
'description' => 'Billing and Announcements SSO',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later
$results = localAPI($command, $postData, $adminUsername);
print_r($results);
示例响应 JSON
{
"result": "success",
"credentialId": "1",
"clientIdentifier": "COMPANY-NAME.SQxOYrZOUTQC8YTkLQuQ0w==",
"clientSecret": "60XScB\/W8zzxtciWlvX8+OoO4ZAQj8dNLeFIulRlYhDgksrSJd0Olv+X7wyoJEWEOpZ9IivCaySN7s+\/a++Tlg=="
}
错误响应
可能的错误条件响应包括:
- 需要有效的授权类型。
- 请求的授权类型“x” 无效。
- 需要客户端凭据的名称。
- 单个 sign-on 授权类型需要服务 ID。
- 至少需要一个有效范围。
- 请求的范围 “x” 无效。
- 需要有效的服务 ID。
- 服务 ID 未与有效客户端关联。
相关用法
- PHP WHMCS CreateOrUpdateTLD用法及代码示例
- PHP WHMCS CreateProject用法及代码示例
- PHP WHMCS CreateSsoToken用法及代码示例
- PHP WHMCS CreateInvoice用法及代码示例
- PHP WHMCS CreateQuote用法及代码示例
- PHP WHMCS CreateClientInvite用法及代码示例
- PHP WHMCS ClientAreaPageDownloads用法及代码示例
- PHP WHMCS ClientAreaHeaderOutput用法及代码示例
- PHP WHMCS CartTotalAdjustment用法及代码示例
- PHP WHMCS ClientAreaPageSupportTickets用法及代码示例
- PHP WHMCS ClientAreaPageDomainDNSManagement用法及代码示例
- PHP WHMCS ClientAreaPageAffiliates用法及代码示例
- PHP WHMCS ClientAreaPageViewInvoice用法及代码示例
- PHP WHMCS ClientAreaPageProductsServices用法及代码示例
- PHP WHMCS CustomFieldSave用法及代码示例
- PHP WHMCS ClientAreaPageDomainRegisterNameservers用法及代码示例
- PHP CachingIterator __construct()用法及代码示例
- PHP WHMCS ClientAreaPageUnsubscribe用法及代码示例
- PHP WHMCS ClientAreaPageConfigureSSL用法及代码示例
- PHP WHMCS ClientAreaPageDomainDetails用法及代码示例
- PHP WHMCS ClientAreaPageAddonModule用法及代码示例
- PHP WHMCS ClientAreaPageContact用法及代码示例
- PHP WHMCS ClientAreaPageSecurity用法及代码示例
- PHP WHMCS ClientAreaPage用法及代码示例
- PHP CachingIterator getCache()用法及代码示例
注:本文由纯净天空筛选整理自whmcs.com大神的英文原创作品 CreateOAuthCredential。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。