私はLivecoding.tvからデータを取得しようとしていましたが、私は現在、私がtwitch APIに使っていたOauth2コントローラを再利用しています。Guards and Form + Laravelの基本認証の問題
誰かがわからない場合は、のOauthで使用されるフローは次のとおりです。
アプリのコードを持つサードパーティのOAuthリンクにユーザーをリダイレクトします。
ユーザ許可。承認されたトークンを使用して、もう一度あなたのウェブサイトにリダイレクト
ユーザー、あなたがステップ3で今すぐなど、あなたのリフレッシュトークンを取得するために第三者に
を投稿することができますことを、私はいくつかに実行しています問題。ここでは、開発者による記述と例は次のとおりです。ユーザ名としてapplication_codeを使用してhttps://www.livecoding.tv/o/token/
ヘッダー
A HTTPベーシック認証、およびに見られるように、パスワードとしてapplication_secret:トークンを取得
以下の例。
POSTボディ
code=EXAMPLE Token gotten from redirect
grant_type=Your grant type (authorization_type)
redirect_uri=Your redirect URL
そして、ここで働いカールリクエストのドキュメントからの例cURLの要求です。
curl -X POST -d "grant_type=authorization_code&code=Php4iJpXGpDT8lCqgBcbfQ2yzhB0Av&client_id=vCk6rNsC&redirect_uri=http://localhost/externalapp" -u"vCk6rNsC:sfMxcHUuNnZ" https://www.livecoding.tv/o/token/
は、だから私は箱から出して働いている、ポストマン(https://www.getpostman.com/)でこれを作ってみました、私はその後、私は何かを逃していたかどうかを確認するために、PHPにこれを変換するために、ポストマンに尋ねました。ここで働くポストマンリクエストの結果は次のとおりです。
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.livecoding.tv/o/token/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "code=SOMECODE&client_id=SOMECLIENTID&redirect_uri=SOMEURL&grant_type=authorization_code",
CURLOPT_HTTPHEADER => array(
"authorization: Basic U09NRVVTRVI6U09NRVBBU1NXT1JE",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"postman-token: c8df4bbc-cbd0-73eb-df35-80210989db33"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
私は、これはすぐに出て働いかなり満足だったので、私はただがつがつ食うクライアントがすでに単収縮のOauthのために働く、同じことを行うために必要な、ここにありますそのために私のコードは:
{
$providers = ServiceProvider::findOrFail(2);
$client = new Client([
'base_uri' => $providers->oauth_url . '/token/',
'form_params' => [
'code' => $token,
'grant_type' => 'authorization_code',
'client_id' => $providers->application_code,
'redirect_uri' => $providers->redirection_url
],
'auth' => [
'somestring',
'someotherstring',
],
'headers' => [
'Content type' => 'application/x-www-form-urlencoded',
'cache-control' => 'no-cache'
]
]);
$response = $client->request('POST');
return ($response);
}
これはちょうど401で私を返しますので、私はいくつかのデバッグを行うことを決めた、と私はそれが送信される直前に、それを停止する場合は、ここに来るの要求は、次のとおりです。
Client {#637 ▼
-config: array:10 [▼
"base_uri" => Uri {#676 ▼
-scheme: "https"
-userInfo: ""
-host: "www.livecoding.tv"
-port: null
-path: "/o/token/"
-query: ""
-fragment: ""
}
"form_params" => array:4 [▼
"code" => "SOMECODE"
"grant_type" => "authorization_code"
"client_id" => "SOMECLIENTID"
"redirect_uri" => "http://REDIRECTURI"
]
"auth" => array:2 [▼
0 => "SOMECLIENTID"
1 => "SOMECLIENTSECRET"
]
"headers" => array:3 [▼
"Content type" => "application/x-www-form-urlencoded"
"cache-control" => "no-cache"
"User-Agent" => "GuzzleHttp/6.2.1 curl/7.26.0 PHP/5.6.27-1~dotdeb+7.1"
]
"handler" => HandlerStack {#664 ▼
-handler: Closure {#671 ▼
class: "GuzzleHttp\Handler\Proxy"
parameters: {▼
$request: {▼
typeHint: "Psr\Http\Message\RequestInterface"
}
$options: {▼
typeHint: "array"
}
}
use: {▼
$default: Closure {#669 ▼
class: "GuzzleHttp\Handler\Proxy"
parameters: {▼
$request: {▼
typeHint: "Psr\Http\Message\RequestInterface"
}
$options: {▼
typeHint: "array"
}
}
use: {▼
$default: CurlMultiHandler {#634 ▼
-factory: CurlFactory {#667 ▼
-handles: []
-maxHandles: 50
}
-selectTimeout: 1
-active: null
-handles: []
-delays: []
}
$sync: CurlHandler {#666 ▼
-factory: CurlFactory {#665 ▼
-handles: []
-maxHandles: 3
}
}
}
file: "/LARAVELPATH/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php"
line: "25 to 29"
}
$streaming: StreamHandler {#670 ▼
-lastHeaders: []
}
}
file: "LARAVELPATH/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php"
line: "49 to 53"
}
-stack: array:4 [▼
0 => array:2 [▼
0 => Closure {#672 ▼
class: "GuzzleHttp\Middleware"
parameters: {▶}
file: "LARAVELPATH/vendor/guzzlehttp/guzzle/src/Middleware.php"
line: "54 to 69"
}
1 => "http_errors"
]
1 => array:2 [▼
0 => Closure {#673 ▼
class: "GuzzleHttp\Middleware"
parameters: {▶}
file: "LARAVELPATH/vendor/guzzlehttp/guzzle/src/Middleware.php"
line: "148 to 150"
}
1 => "allow_redirects"
]
2 => array:2 [▼
0 => Closure {#674 ▼
class: "GuzzleHttp\Middleware"
parameters: {▶}
file: "LARAVELPATH/vendor/guzzlehttp/guzzle/src/Middleware.php"
line: "27 to 43"
}
1 => "cookies"
]
3 => array:2 [▼
0 => Closure {#675 ▼
class: "GuzzleHttp\Middleware"
parameters: {▶}
file: "LARAVELPATH/vendor/guzzlehttp/guzzle/src/Middleware.php"
line: "216 to 218"
}
1 => "prepare_body"
]
]
-cached: null
}
"allow_redirects" => array:5 [▼
"max" => 5
"protocols" => array:2 [▼
0 => "http"
1 => "https"
]
"strict" => false
"referer" => false
"track_redirects" => false
]
"http_errors" => true
"decode_content" => true
"verify" => true
"cookies" => false
]
}
ここに見られるように、ここには「auth」というパラメータがあり、Guzzleに記載されている基本認証ではありません。http://docs.guzzlephp.org/en/latest/request-options.html#auth
正しい値が入力されていますが、
私はちょうどdd($client)
でした、私はすべての答えを与えるかわからないデバッグのために?
他の可能性はbase64でエンコードして(一般的な基本認証のように)、 "Authorization"ヘッダを手動で追加してみましたが、試してみましたが、私が正しく動作しているかどうかはわかりませんdo:
$credentials = base64_encode($clientvariable . ':' . $clientsecretvariable)
これは正しい方法でしょうか?私がむしろ最後の手段として私はむしろ私がGuhで働くauthパラメタを得ないなら、これを使うでしょうが。
私はGuzzleと基本認証についての他のStackoverflowに関する質問をしています。はい、私はそれらを読んでいます。うまくいけば私はそれを示すのに十分な情報を提供しています。