Firebase Web: данные аутентификации телефона для перенаправления - PullRequest
0 голосов
/ 19 мая 2018

Как я могу передать idToken в redirectUrl?вот так: http://example.com/?token=[idToken]

Это мой код:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        Firebase Phone Number Auth
    </title>
</head>

<body>
    <form>
        <input type="text" id="verificationcode" value="enter verification">
        <input type="button" value="Submit" onclick="myFunction()">
    </form>
    <div id="recaptcha-container"></div>
    <script src="https://www.gstatic.com/firebasejs/4.8.1/firebase.js"></script>
    <script>
        // Initialize Firebase
        var config = {
            apiKey: "*******************",
            authDomain: "*******.firebaseapp.com",
            databaseURL: "https://*******.firebaseio.com",
            projectId: "*******",
            storageBucket: "*******.appspot.com",
            messagingSenderId: "*******"
        };
        firebase.initializeApp(config);
    </script>
    <script type="text/javascript">
        window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', {
            'size': 'invisible',
            'callback': function (response) {
                onSignInSubmit();
            }
        });
        firebase.auth().signInWithPhoneNumber("+1(111) 111-1111", window.recaptchaVerifier)
            .then(function (confirmationResult) {
                window.confirmationResult = confirmationResult;
                a(confirmationResult);
            });
        var myFunction = function () {
            window.confirmationResult.confirm(document.getElementById("verificationcode").value)
                .then(function (result) {}, function (error) {
                    alert(error);
                });
        };
    </script>
</body>
</html>

Я нашел это: https://github.com/firebase/firebaseui-web/issues/188, но не помог мне не работать с моим кодом!

1 Ответ

0 голосов
/ 21 мая 2018

Это довольно просто.Как только подтверждение и результат разрешаются, и вы входите в систему, пользователь запускает следующую логику:

firebase.auth().currentUser.getIdToken().then(function(idToken) {
    // You can add the ID token to the header, or postBody, etc.
    // For simplicity, let's append it to the URL.
    window.location.assign('http://yourSignInSuccessUrl/?idToken=' + idToken);
  }).catch(function(error) {
    console.log(error);
  });

Обратите внимание, что лучше проходить через заголовок или тело POST.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...