title: Firebase.auth error with 400 bad request
body: <p>I found a strange error while I developing system using Firebase with service url contains user data.</p>
  
  <p>User data is below.</p>
  
  <pre><code>    {
        "uid": "kt9Hcp2FbYbBvvIeSHHa1RbvHcv2",
        "displayName": "Anonymous 901",
        "photoURL": null,
        "email": null,
        "emailVerified": false,
        "identifierNumber": null,
        "isAnonymous": true,
        "providerData": [
  
        ],
        "apiKey": "MyApiKeyString",
        "appName": "MyAppName",
        "authDomain": "my.auth.domain",
        "stsTokenManager": {
          "apiKey": "MyApiKeyString",
          "refreshToken": "refreshTokenString",
          "accessToken": "accessTokenString",
          "expirationTime": 1532451863076
        },
        "redirectEventId": null
      }
  </code></pre>
  
  <p>I encode the above anonymous user data and include it in the service url.
  ( <a href="http://myserviceurl?userdata=encodedUserData" rel="nofollow noreferrer">http://myserviceurl?userdata=encodedUserData</a> )</p>
  
  <p>Inside the system receives that url, firebase creates a user object with that user data contained in the url.</p>
  
  <p>The purpose of this url is to use specific user's information in any browser.</p>
  
  <p>However, when I call that service url, sometimes system creates user object well, sometimes got error -
  400 Bad request errors with
  <a href="https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key=MyApiKeyString" rel="nofollow noreferrer">https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key=MyApiKeyString</a></p>
  
  <p>And error data is below,</p>
  
  <pre><code>    {
        "error": {
          "code": 400,
          "message": "TOKEN_EXPIRED",
          "errors": [
            {
              "message": "TOKEN_EXPIRED",
              "domain": "global",
              "reason": "invalid"
            }
          ]
        }
      }
  </code></pre>
  
  <p>Few hours later it works well, I changed nothing though. </p>
  
  <p>I could not find the exact error point, but I suspect error occurs while observing authentication state or before this step.</p>
  
  <p>Here is code snipets</p>
  
  <pre><code>    @bind
      private makeUserLoadingPromise(): Promise&lt;void&gt; {
        let unSubscribe: () =&gt; void;
        return new Promise&lt;void&gt;((resolve, _reject) =&gt; {
          const onInitialized = this.makeOnInitializedAuthStateChanged(resolve);
          unSubscribe = this.auth.onAuthStateChanged(onInitialized);
        }).then(() =&gt; {
          unSubscribe();
          this.auth.onAuthStateChanged(this.onAuthStateChanged);
        });
      }
  
      @bind
      private makeOnInitializedAuthStateChanged(resolve: () =&gt; void) {
        return (user: firebase.User | null) =&gt; {
          this.user = user;
          resolve();
        };
      }
  
      @bind
      private onAuthStateChanged(user: firebase.User | null) {
        this.user = user;
      }
  </code></pre>
  
  <p>Or maybe it relates with expirationTime?</p>
  
  <p>I couldn't find any hints about this situation.</p>
  
  <p>Any advice would be appreciated.</p>