Post

Replies

Boosts

Views

Activity

Reply to Sign In with Apple - Your request could not be completed due to an error. Try again later.
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; } `
Topic: App & System Services SubTopic: General Tags:
Feb ’22
Reply to Sign in with Apple JS - React - How to configure the redirectURI?
New data: I'm working on a new development server, different from the one that I did my original non-React implementation of this process on. This week, I brought that original process over to the new server -- and it is now failing in exactly the same way as the React app. It appears that the problem is more likely in the server configuration, rather than in the React implementation. (This is an in-house server, managed by Corporate IT. The old server was Apache. I know that the new one isn't using Apache, but don't know what it is running...)
Topic: App & System Services SubTopic: General Tags:
Feb ’22
Reply to Sign in with Apple JS - React - How to configure the redirectURI?
For anyone who runs into this error, I finally got it fixed -- but not by changing the configuration of my redirect URL. My problem was the Cross-Origin-Opener-Policy header on the web server -- and the tech with access to that changed it to allow "same-origin-allow-popups" In regards to the redirect URL itself, since I am using a one-page React App for my website I just have it like the following: https://www.mysite.com/ (The ending slash seems to be a must...) To set it in your Apple Developer account, go to "Certificates, Identifiers & Profiles" --> then choose "Identifiers" in the left hand menu --> then select "Service IDs" over on the top right. (The default is "App IDs") From there you can add or edit your Sign In with Apple configuration, including the URLs...
Topic: App & System Services SubTopic: General Tags:
Apr ’22