Slim Framework 3を使用して、小さな内部APIを作成してフェイスブックデータを取得しています。 APIにアクセスできるユーザーは約30人です。Slim 3でアプリケーションを実行する前にusertokenを認証します
私はウェブサイトからのユーザートークンの送信によってユーザーを認証したいと思います。そのトークンは、アプリケーションの実行前にチェックされます。
ユーザーのトークンはDBに設定されており、ユーザーがAPIを要求しているときにトークンがGETと共に送信され、DBとGETトークンに一致するものがある場合、ユーザーはAPIを使用しないと、ユーザーはアクセスを禁止する必要があります。
私はFacebookのデータを取得するために、これを使用しています:
$app->get('/fbdata/campaign/{campaign}/bankarea/{bankarea}/from/{from}/to/{to}/utoken/{utoken}', function(Request $request, Response $response) {
$bd = new BankAppData();
$getFb = new GetFacebookData();
$bankarea = $request->getAttribute('bankarea');
$campaign = $request->getAttribute('campaign');
$appid = $bd->BankData($bankarea)->appid;
$appsecret = $bd->BankData($bankarea)->appsecret;
$fbtoken = $bd->BankData($bankarea)->fbtoken;
$dateFrom = $request->getAttribute('from');
$dateTo = $request->getAttribute('to');
$getFb->FetchData($appid, $appsecret, $fbtoken, $campaign, $bankarea, "act_XXXX", $dateFrom, $dateTo);
});
は、これはうまく動作しますが、私は上記を実行する前にutoken
をチェックするためAuthenticationHandler
クラスを使用します。
私はそれを$app->add(new SNDB\AuthenticationHandler());
を使って追加していますが、私は自分のAuthenticationHandlerクラスのURLからどのようにしてutokenを得ることができるのか分かりません。
基本的に私はあなたがmiddleware concept from slim3を見てみる必要があります
function Authenticate() {
if($dbToken != $utoken) {
//No access - app will just stop doing anything else
} else {
//You have access - just continue what you was trying to do
}
}