我正在使用OAuth2授权应用程序的Facebook帐户。我刚刚发现,如果访问 token 请求失败,file_get_contents
将显示完整的请求URL,其中包含敏感数据,例如 secret 应用程序ID(client_id/client_secret)。
如何处理这类事情?有没有办法显示警告消息但不暴露那些路径?
Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=123&redirect_uri=https%3A%2F%2Fwww.example.com%2Foauth%2Ffacebook.php&client_secret=123&code=123) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in oauth/facebook.php on line 113
最佳答案
使用try catch块在php中轻柔地处理错误。由于您使用的是Facebook OAuth,因此只需在try catch中包含方法/函数,如下所示try {
"...facebook oauth function here..."
}
catch (Exception $e) {
echo $e->getMessage();
}
如果这可以解决您的问题,请告诉我。
问候,
HBK
关于php - PHP警告消息公开了OAuth应用的 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22870537/