Sign In with Apple - Your request could not be completed due to an error. Try again later.

I've already read the fixes suggested at the link below -- and double-checked my code regarding each:

https://developer.apple.com/forums/thread/117531


I'm doing a React web page, using the npm package: react-apple-signin-auth for the Sign In with Apple feature. (And I have Sign In with Google already working...)

When previewing the page (http://localhost:3000/), the pop-up displays and I get the prompt to Sign In with Apple. The process works all the way through until the point at which it is supposed to return the data back to my site. (Which is better than I expected in that mode.)

When I build the page and push it up to my development web server, the pop-up displays -- but I get an error saying: "Your request could not be completed due to an error. Try again later."

(Note: I can't point you to the development site, because corporate keeps it behind a local firewall.)

Any pointers would be greatly appreciated.

~JD

Answered by jdw814 in 703811022

This ended up being a mess, so I opened a new question that should be easier for someone to help me with.

Here's a cleaned up sample of the code I am using:

`import React from 'react'; import $ from 'jquery';

import AppleSignin from 'react-apple-signin-auth'; import { appleAuthHelpers } from 'react-apple-signin-auth';

var randomNonce = '';

const responseApple = () => { console.log('Called responseApple');

if (0 == randomNonce.length) { randomNonce = randomString(); console.log('responseApple - randomNonce', randomNonce); }

try { return appleAuthHelpers.signIn({ authOptions: { clientId: '<>', redirectURI: '<>', nonce: randomNonce, usePopup: true, }, onSuccess: (response) => console.log('responseApple - response', response), /* Will be appleSignInReturn */ onError: (error) => console.log('responseApple - error', error), }); } catch (error) { console.log('responseApple - catch error', error); //handle error. } }

class AppleSignInButton extends React.Component { render() { return ( ); } }

export default AppleSignInButton;

const AppleSignInBtn = ({ ...rest }) => ( /** Apple Signin button / <AppleSignin /* Auth options passed to AppleID.auth.init() */ authOptions={{ clientId: '<>', scope: 'name email', redirectURI: '<>', state: 'new_user', nonce: randomNonce, usePopup: true, }}

/** General props */ uiType="light" /** className */ className="apple-auth-btn" /** Allows to change the button's children, eg: for changing the button text */ buttonExtraChildren="&nbsp;Apple&nbsp;" /** Called upon signin success in case authOptions.usePopup = true -- which means auth is handled client side */ onSuccess={() => responseApple} // default = undefined /** Called upon signin error */ onError={(error) => console.log('AppleSignInBtn onError error', error)} // default = undefined /** Skips loading the apple script if true */ skipScript={false} // default = undefined /** Checkout README.md for further customization props. */ /** Spread rest props if needed */ {...rest}

/> );

function appleSignInReturn(appleData) { console.log("AppleSignInReturn called"); console.log('appleData', appleData);

let signInSuccess = false; let authData = (typeof appleData.authorization !== "undefined") ? appleData.authorization : []; let rtnToken = (typeof authData.id_token !== "undefined") ? authData.id_token : '';

let tokenData = parseJwt(rtnToken); let rtnNonce = (typeof tokenData.nonce !== "undefined") ? tokenData.nonce : '';

console.log('appleSignInReturn - rtnNonce', rtnNonce, 'randomNonce', randomNonce);

if (rtnNonce == randomNonce) { //console.log('appleSignInReturn - Nonces match'); } else { //TODO: SIGN IN FAIL...? }

let appleEmail = (typeof tokenData.email !== "undefined") ? tokenData.email : '';

let appleEmailVer = 0; if (typeof tokenData.email_verified !== "undefined" && tokenData.email_verified === 'true') { appleEmailVer = 1; } console.log('appleSignInReturn - appleEmailVer', appleEmailVer);

let userData = (typeof appleData.user !== "undefined") ? appleData.user : []; console.log('appleSignInReturn - userData', userData);

let rtnName = (typeof userData.name !== "undefined") ? userData.name : []; console.log('appleSignInReturn - rtnName', rtnName);

let appleFName = (typeof rtnName.firstName !== "undefined") ? rtnName.firstName : ''; let appleLName = (typeof rtnName.lastName !== "undefined") ? rtnName.lastName : ''; console.log('appleSignInReturn - appleFName', appleFName, 'appleLName', appleLName);

if (appleFName.length > 0 && appleLName.length > 0) { signInSuccess = true; }

if (appleEmail.length == 0 && typeof userData.email !== "undefined") { appleEmail = userData.email; console.log('appleSignInReturn - appleEmail', appleEmail); }

if (appleEmail.length > 0) { signInSuccess = true; }

if (signInSuccess) { console.log("Should start updating Apple fields - First name", appleFName); <> } }

/************************************************************************/

function parseJwt(token) { let base64Url = token.split('.')[1]; let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');

let jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join(''));

return JSON.parse(jsonPayload); }

function randomString() { //define a variable consisting alphabets in small and capital letter, plus numerical digits let characters = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz0123456789";

//specify the length for the new string let lenString = 7; let rNum = 0; let rtnString = '';

//loop to select a new character in each iteration for (var i = 0; i < lenString; i++) { rNum = Math.floor(Math.random() * characters.length); rtnString += characters.substring(rNum, rNum + 1); }

//display the generated string return rtnString; } `

That definitely did not go in the way I thought it would...

Accepted Answer

This ended up being a mess, so I opened a new question that should be easier for someone to help me with.

Sign In with Apple - Your request could not be completed due to an error. Try again later.
 
 
Q