[英]Apple Sign In stacks in PHP Function for Capacitor 4
I am having a problem with my Sign In Apple function on Capacitor 4.我在 Capacitor 4 上登录 Apple function 时遇到问题。
The error it give is for my backend PHP function它给出的错误是针对我的后端 PHP function
Failed to load resource: the server responded with a status of 500 ()
ERROR
HttpErrorResponse
error: null
headers: HttpHeaders
lazyInit: function()
arguments: TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.
caller: TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.
length: 0
name: ""
Function Prototype
lazyUpdate: null
normalizedNames: Map {} (0)
HttpHeaders Prototype
message: "Http failure response for https://project.com/project_api/api/sign_in_with_apple: 500 OK"
name: "HttpErrorResponse"
ok: false
status: 500
statusText: "OK"
url: "https://project.com/project_api/api/sign_in_with_apple"
and the.network error和.network错误
Summary
URL: https://project.com/project_api/api/sign_in_with_apple
Status: 500
Source: Network
Address: 185.35.33.55:553
Initiator:
zone.js:3454
Request
:method: POST
:scheme: https
:authority: project.com
:path: /project_api/api/sign_in_with_apple
Accept: application/json, text/plain, */*
Content-Type: application/x-www-form-urlencoded
Origin: capacitor://localhost
Accept-Encoding: gzip, deflate, br
Host: rovespier.com
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
Content-Length: 1074
Accept-Language: el-GR,el;q=0.9
Connection: keep-alive
Response
:status: 500
Content-Type: text/html; charset=UTF-8
Pragma: no-cache
Set-Cookie: PHPSESSID=9ca0e5311a0376ade70056525d9a765f; path=/
X-Content-Type-Options: nosniff, nosniff
Access-Control-Allow-Origin: *
Date: Mon, 30 Jan 2023 09:20:35 GMT
X-XSS-Protection: 1; mode=block
Content-Length: 0
Cache-Control: no-store, no-cache, must-revalidate
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Server: nginx
Request Data
MIME Type: application/x-www-form-urlencoded
login_data[response][identityToken]: eyJraWQiOiJmaDZCczhDIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLnJvdmVzcGllci5tb2JpbGUiLCJleHAiOjE2NzUxNTY4MzQsImlhdCI6MTY3NTA3MDQzNCwic3ViIjoiMDAwNjc0LjZiMDUzYzSI6Im5vbmNlIiwiY19oYXNoIjoiZUY2WEdNRDhtYzViT3o0U0JVQnF5QSIsImVtYWlsIjoic2ltb25pb2FubmlkZXNAaG90bWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJhdXRoX3RpbWUiOjE2NzUwNzA0MzQsIm5vbmNlX3N1cHBvcnRlZCI6dHJ1ZX0.bvXBlch8O-H690PsIFNZpJqauCcdozuZggt0I1nGY0PHQ075OSHKYlUXvsY_aOTIEzxyHnrygOAtuk_OkzqmwPplQGfOKZPyGFWBo2xHPChysVX-VmRk81s3Qkza76Ty-tmVymcdTQ-59Eumq0bn7BH_X8mWEdr6NLGP5JOw7kjAGKBVJbHZ9fgUd72KDgFWiHOF-brEkXABL4IgeDqOhAuDP30bAyRFbtDWme5GPcnZU3t13qLDLEDPSK1jrl3X-OU8d2WOALBrnaJhmPw8z7H20Nx61vuio7KoCRPqD_3HT_Plga7dHT43DkQ
login_data[response][authorizationCode]: cf7d3de8d4c7f4277a128d2453423235.0.swxu.KmQXI352ayadDUh3cBGCjA
login_data[response][user]: 000674.6b053c49f8cc45b1bce5623f23343.1836
app_version: 1.0.1
timezone_offset: 120
login.ts function登录.ts function
async checkApple(login_data) {
const loader = await this.loadingCtrl.create({
spinner: 'bubbles',
//content: 'Loading...',
//dismissOnPageChange: true
});
loader.present();
this.userData.appleLogin(login_data).pipe(
map((data: any) => {
loader.dismiss();
if (data.success) {
this.userData.setSession('HAS_LOGGED_IN', true);
this.userData.setUserData(data.userData);
this.router.navigate(["app/tablinks/home"]);
//this.events.publish('user:signup');
//this.navCtrl.setRoot('TabsPage', {}, { animate: true, direction: 'forward' });
}
else {
}
},
err => {
loader.dismiss();
})
).subscribe()
}
loginApple() {
let options: SignInWithAppleOptions = {
clientId: 'com.projectr.mobile',
redirectURI: 'https://www.project.com/',
scopes: 'email name',
state: '12345',
nonce: 'nonce',
};
SignInWithApple.authorize(options)
.then((result: SignInWithAppleResponse) => {
console.log(result);
this.checkApple(result);
})
.catch(error => {
// Handle error
});
(<any>window).cordova.plugins.SignInWithApple.signin(
{ requestedScopes: [0, 1] },
(succ) => {
console.log('APPLE', JSON.stringify(succ));
//why dont go to start page? ah ok where?there but it is under the tabs lol see the tabs?
this.checkApple(succ);
//succ.email
//alert(JSON.stringify(succ))
},
(err) => {
console.error(err)
console.log(JSON.stringify(err))
}
)
}
user-data.ts function用户数据.ts function
appleLogin(login_data) {
let device = {};
if (this.platform.is('cordova')) {
/*device = {
platform: this.device.platform,
uuid: this.device.uuid,
cordova: this.device.cordova,
model: this.device.model,
manufacturer: this.device.manufacturer,
version: this.device.version,
};*/
}
var timezone_offset = new Date().getTimezoneOffset();
timezone_offset = timezone_offset == 0 ? 0 : -timezone_offset;
const url = this.appData.getApiUrl() + 'sign_in_with_apple';
const data = this.jsonToURLEncoded({
login_data: login_data,
device: device,
app_version: this.appData.APP_VERSION,
timezone_offset: timezone_offset
});
return this.http.post(url, data, { headers: this.options });
};
sign_in_with_apple PHP FUNCTION sign_in_with_apple PHP FUNCTION
function sign_in_with_apple()
{
$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
$response['success'] = false;
$loginData = $_POST['login_data'];
$identityToken = $loginData['identityToken'];
$clientUser = $loginData['user'];
$clientAuthorizationCode = $loginData['authorizationCode'];
$appleSignInPayload = ASDecoder::getAppleSignInPayload($identityToken);
/**
* Obtain the Sign In with Apple email and user creds.
*/
$email = $appleSignInPayload->getEmail();//for username put givenname and family name all together without space
$user = $appleSignInPayload->getUser();
/**
* Determine whether the client-provided user is valid.
*/
$isValid = $appleSignInPayload->verifyUser($clientUser);
if ($isValid) {
// Check if email exists
try
{
$username = strstr($email, '@', true);
$db = getDB();
$sql = "SELECT uid,notification_created,username,name,profile_pic,tour,email, api_signature,first_name,last_name, artisticBehaviour,location,bio,friend_count
FROM users WHERE (username=:username or email=:email) AND status='1' ";
$stmt = $db->prepare($sql);
$stmt->bindParam("username", $username, PDO::PARAM_STR);
$stmt->bindParam("email", $email, PDO::PARAM_STR);
$stmt->execute();
$mainCount = $stmt->rowCount();
$userData = $stmt->fetch(PDO::FETCH_OBJ);
$created = time();
if ($mainCount == 0) {
$api_signature = md5(time() . $username . rand(1, 1000));
$status = '1';
if (SMTP_CONNECTION > 0) {
$status = '0';
}
/*Inserting user values*/
$email_active_code = $email . time();
$sql1 = "INSERT INTO users(username,password,email,last_login,email_activation,status, api_signature)VALUES(:username,:password,:email,:created,:email_activation,:status,:api_signature)";
$stmt1 = $db->prepare($sql1);
$stmt1->bindParam("username", $username, PDO::PARAM_STR);
$password = hash('sha256', $signupData['password']);
$stmt1->bindParam("password", $password, PDO::PARAM_STR);
$stmt1->bindParam("email", $email, PDO::PARAM_STR);
$stmt1->bindParam("created", $created);
$stmt1->bindParam("status", $status);
$stmt1->bindParam("api_signature", $api_signature);
$stmt1->bindParam("email_activation", $email_active_code);
$stmt1->execute();
$stmt2 = $db->prepare("SELECT uid,notification_created,username,name,first_name,last_name, profile_pic,tour,email,friend_count FROM users WHERE username=:username");
$stmt2->bindParam("username", $data->username, PDO::PARAM_STR);
$stmt2->execute();
$userData = $stmt2->fetchAll(PDO::FETCH_OBJ);
$uid = $userData[0]->uid;
$stmt3->bindParam("created", $time, PDO::PARAM_STR);
$me = 'me';
$stmt3->bindParam("me", $me, PDO::PARAM_STR);
$stmt3->execute();
$userData = internalUserDetails($email); // this one where isit?
$response['success'] = true; // 2
$response['userData'] = $userData;
} else { // sign in
$photos_query = $db->query("SELECT id FROM user_uploads WHERE uid_fk='$uid' and group_id_fk='0'");
$photos_count = $photos_query->rowCount(); /* Photos Count */
$updates_query = $db->query("SELECT msg_id FROM messages WHERE uid_fk='$uid' and group_id_fk='0'");
$updates_count = $updates_query->rowCount(); /* Updates Count */
$time = time();
$updates_query = $db->query("UPDATE users SET last_login='$time',photos_count='$photos_count',updates_count='$updates_count' WHERE uid='$uid'");
$userData->profile_pic = profilePic($userData->profile_pic);
$userData->configurations = configurations();
$response['success'] = true; // 2
$response['userData'] = $userData;
}
} catch (PDOException $e) {
echo '{"error":{"text35":' . $e->getMessage() . '}}';
}
}
else {
$response['error'] = 'Please allow access to your email';
}
echo json_encode($response);
}
Your.network error block has - Your.network 错误块有 -
Request Data
MIME Type: application/x-www-form-urlencoded
login_data[response][identityToken]: eyJraWQiOiJmaDZCczhDIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLnJvdmVzcGllci5tb2JpbGUiLCJleHAiOjE2NzUxNTY4MzQsImlhdCI6MTY3NTA3MDQzNCwic3ViIjoiMDAwNjc0LjZiMDUzYzSI6Im5vbmNlIiwiY19oYXNoIjoiZUY2WEdNRDhtYzViT3o0U0JVQnF5QSIsImVtYWlsIjoic2ltb25pb2FubmlkZXNAaG90bWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJhdXRoX3RpbWUiOjE2NzUwNzA0MzQsIm5vbmNlX3N1cHBvcnRlZCI6dHJ1ZX0.bvXBlch8O-H690PsIFNZpJqauCcdozuZggt0I1nGY0PHQ075OSHKYlUXvsY_aOTIEzxyHnrygOAtuk_OkzqmwPplQGfOKZPyGFWBo2xHPChysVX-VmRk81s3Qkza76Ty-tmVymcdTQ-59Eumq0bn7BH_X8mWEdr6NLGP5JOw7kjAGKBVJbHZ9fgUd72KDgFWiHOF-brEkXABL4IgeDqOhAuDP30bAyRFbtDWme5GPcnZU3t13qLDLEDPSK1jrl3X-OU8d2WOALBrnaJhmPw8z7H20Nx61vuio7KoCRPqD_3HT_Plga7dHT43DkQ
login_data[response][authorizationCode]: cf7d3de8d4c7f4277a128d2453423235.0.swxu.KmQXI352ayadDUh3cBGCjA
login_data[response][user]: 000674.6b053c49f8cc45b1bce5623f23343.1836
app_version: 1.0.1
timezone_offset: 120
which shows another layer (response) in your login_data so you should be getting some array key errors in your PHP logs, before the fatal exception -它在你的 login_data 中显示了另一层(响应)所以你应该在你的 PHP 日志中得到一些数组键错误,在致命异常之前 -
Warning: Undefined array key "identityToken" in ...
Warning: Undefined array key "user" in ...
Warning: Undefined array key "authorizationCode" in ...
You need to change the initial assignment of $login_data to -您需要将 $login_data 的初始分配更改为 -
$loginData = $_POST['login_data']['response'];
There may well be further errors after this.在此之后很可能还有更多的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.