我正在尝试将OAuth 2客户端实施到Workday,而我却试图请求令牌。我可以调用授权端点并使用授权代码重定向到我的回调,但是当我尝试将授权代码发布到令牌端点时,我得到:
"{\"error\" : \"application=service - invalid_request\"}"
我在request_uri上尝试过不同的URL编码组合。我试过传递一个状态参数。我甚至已经去了代理电话,以确保我实际上发送了正确的信息。这是我编写的用于尝试和检索令牌的PHP代码。
function callback() {
$code = $_GET["code"];
log_message('info', 'Using code: ' . $code);
$url = "https://wd5-impl-services1.workday.com/ccx/oauth2/<redacted>/token";
$data = array(
'client_id' => '<redacted>',
'client_secret' => '<redacted>',
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => 'https://<redacted>/account/callback'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
$result = curl_exec($curl);
log_message('info', json_encode(curl_getinfo($curl)));
curl_close($curl);
log_message('info', json_encode($result));
#redirect(base_url()."account/login");
}
我有点迷失了什么是错的。我已经梳理了所有论坛,并且我试图与其他OAuth 2服务器的对话进行比较,但我找不到任何有关我的具体问题的内容。还有其他人成功地使用Workday吗?
答案 0 :(得分:1)
尝试一下...
它对我有用:
curl -X POST \
https://wd2-impl-services1.workday.com/ccx/oauth2/ <tenant> /token \
-H 'Authorization: Basic T0RJM1pqa3pZbVV0WXpBeU15MDBZV0kwTFRnMU4yRXROV1UyTW1Wak16ZzFNamxqOmNudzZwbDI3Zmc4eG54YWIxamE1cWR6cHlqMGtkZW9mdmNubjF0czhyN3U2OHpiZ3llOTJyajZvbWhiMjY3ZjlrYzE0ajU3d3F5cHQyNjN5Ymc3N3h3ZXdvc3h2bmVodTc1Mw==' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Host: wd2-impl-services1.workday.com' \
-H 'cache-control: no-cache' \
-H 'content-length: 60' \
-d 'grant_type=authorization_code&code=4pwzdn1vs63alnm1fyas62za6'
其结果是:
{
"refresh_token": "r50ditl18yt0osdfnoasdsadfouwerljsdfkauooiu5h5hvanlkf8ow5n9ugjc3d8wiz99c6xxbi2t8ruqhxhohfzl4jfmuy",
"token_type": "Bearer",
"access_token": "e1zrm1ccwb9werwer6upb3tkp"
}