[英]Oauth2 apple signin on php laravel
我還是個新手,想問一下我正在處理的任務,在這種情況下,我正在使用 oauth2 進行身份驗證,以便能夠訪問蘋果 api,但是使用蘋果登錄時出現錯誤,出現 invalid_client,對於 invalid_client 錯誤,我做了以下方法:
在我嘗試的三個步驟中,我對腳本身份驗證或客戶端 ID 感到懷疑
請告訴我在 client_id 命名或腳本部分中我的錯誤在哪里謝謝你的幫助,對不起我的英語不好我包括我使用的腳本
``
$provider = new Apple([
'clientId' => 'com.example.example',
'teamId' => 'apple-team-id',
'keyFileId' => 'apple-key-file-id',
'keyFilePath' => storage_path('apple-key-file-path'),
'redirectUri' => 'http://localhost:8000/Store/Gold_Store/GoldStore-create',
]);
if(!isset($_POST['code'])){
//jika kita tidak mempunyai authorization code
$authUrl = $provider->getAuthorizationUrl();
$_SESSION['oauth2state'] = $provider->getState();
header('Location: '.$authUrl);
exit;
//check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_POST['state']) || ($_POST['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
}else{
//try to get access token(using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
'code' => $_POST['code']
]);
//Optional: Now u have a token u can look up a user profile data
try {
//we got an access token, lets now get the user's detail
$user = $provider->getResourceOwner($token);
//use these details to create a new profile
printf('hello %s!', $user->getFirstName());
//refresh token
$refreshToken = $token->getRefreshToken();
$refreshTokenExpiration = $token->getRefreshTokenExpires();
} catch (Exception $e) {
//Failed to get user details
exit(':-(');
}
//use this to interact with an API on the users behalf
echo $token->getToken();
}
這是我的 json 結果
``{“錯誤”:“invalid_client”}
invalid_client 錯誤意味着客戶端密碼錯誤,可能是您生成它的方式或您使用的詳細信息的問題。
您可以查看這段代碼以測試 PHP 蘋果登錄
https://gist.github.com/ameen-sarsour/e14a1d5bae5b61080dfdd5b1430c3e10
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.