title: Firebase Phone Auth Error 400
body: <p>Just getting started with Firebase phone auth. Seems pretty slick however I've hit a wall with a bug. </p>
  
  <pre><code> {
   "error": {
    "errors": [
     {
      "domain": "global",
      "reason": "invalid",
      "message": "SESSION_EXPIRED"
     }
    ],
    "code": 400,
    "message": "SESSION_EXPIRED"
   }
  }
  </code></pre>
  
  <p>Starting with the Captcha: (standard documentation code!)</p>
  
  <pre><code>  var applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', {
        'size': 'invisible',
        'callback': function(response) {
  
        },
        'expired-callback': function() {
  
        }
      });
  </code></pre>
  
  <p>Its rendered and the captcha works well.</p>
  
  <p>Next is the sign-in bit where you are sent the auth code to your phone. Works great:</p>
  
  <pre><code>$scope.signInWithPhoneNumber = function signInWithPhoneNumber() {
  
  
          var phoneNumber = "*censored*";
          var appVerifier = window.recaptchaVerifier;
          firebase.auth().signInWithPhoneNumber(phoneNumber, applicationVerifier)
            .then(function (confirmationResult) {
              // SMS sent. Prompt user to type the code from the message, then sign the
              // user in with confirmationResult.confirm(code).
              window.confirmationResult = confirmationResult;
  
  
  
  
              $scope.setConfirmationResult(confirmationResult);
              alert('Result: ' + JSON.stringify(confirmationResult));
            }).catch(function (error) {
            // Error; SMS not sent
            alert('Error: ' + error);
            // ...
          });
        };
  </code></pre>
  
  <p>Finally its the authentication of the code that the user inputs from the text message. Here is when I get the error 400:</p>
  
  <pre><code>$scope.AuthenticateCode = function (code) {
  
  
          var code = String(document.getElementById("auth_code").value);
  
          var confirmationResult = $scope.getConfirmationResult();
          alert(code);
          confirmationResult.confirm(code).then(function (result) {
            // User signed in successfully.
            var user = result.user;
            console.log('Signed In! ' + JSON.stringify(user));
            // ...
          }).catch(function (error) {
            // User couldn't sign in (bad verification code?)
            // ...
          });
  
        }//end of AuthenticateCode
  </code></pre>
  
  <p>The error is coming from the VerifyPhone method: 
  <a href="https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPhoneNumber?key=" rel="nofollow noreferrer">https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPhoneNumber?key=</a><em>censored</em></p>
  
  <p>Any help or ideas?</p>
  
  <p>Many Thanks,
  Kieran</p>