How to use “Sign In with Apple” with Apple JS

2020-07-03 03:44发布

问题:

I would use "Sign In with Apple" in the web via Apple JS. The code example can be found here: https://developer.apple.com/documentation/signinwithapplejs/configuring_your_webpage_for_sign_in_with_apple

The question now is: what is the Client ID and where can I find it. I tested the identifier of the app id on https://developer.apple.com/account/resources/identifiers/list and I tested the identifier of the service id. If I click on the button and verify with Touch ID on my mac, I got the error "AUTH_ALERT_SIGN_UP_NOT_COMPLETED":

This is the used code:

<html>
    <head>
    </head>
    <body>
        <button id="sign-in-with-apple-button"> Sign In with Apple </button>
        <script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
        <script type="text/javascript">
            AppleID.auth.init({
                clientId : 'unknown',
                scope : 'email',
                redirectURI: 'https://mytld/test.php',
                state : 'DE'
            });

            const buttonElement = document.getElementById('sign-in-with-apple-button');
            buttonElement.addEventListener('click', () => {
                AppleID.auth.signIn();
            });
        </script>
    </body>
</html>

I got no request on test.php.

回答1:

Client ID is the "Identifier" of your Service ID that has "Sign In with Apple" enabled:

Apple recommends you make it the following format on the Register a Service ID screen:

We recommend using a reverse-domain name style string (i.e., com.domainname.appname). It cannot contain an asterisk (*).