title: Angular getting Authorization token asynchronously before HTTP calls
body: <p>before posting this i went to many other similar questions and not able to find solutions. like  <a href="https://stackoverflow.com/questions/39373645/angular-2-inject-authorization-token-before-each-http-request">Angular 2 - Inject authorization token before each Http request</a></p>
  
  <p>I am using AWS session which provides me Authorization token for makeing HTTP request. Now getting session can be asynchronous operation depending on need to refresh token. </p>
  
  <p><strong>Problem:</strong>
  I am not able to chain getting session and then making HTTP calls. </p>
  
  <p><strong>Versions</strong> Angular 5, RxJs 5.5.2</p>
  
  <p><strong>AuthService's get session function.</strong> </p>
  
  <pre><code>    getSession(): Observable&lt;any&gt; {
          const sessionOb = new Subject&lt;CognitoUserSession&gt;();
          // AysnFn4session is a callback implementation
          AysnFn4session((err, session) =&gt; { 
                  console.log('Found Session');
                  sessionOb.next(session);
                  sessionOb.complete();
              });
          return sessionOb;
      }
  </code></pre>
  
  <p><strong>API service's get function - Trail 1</strong></p>
  
  <pre><code>get(url: string, options?: RequestOptionsArgs): Observable&lt;Response&gt; {
      return this._authService.getSession().switchMap((session) =&gt; {
        console.log('dasdasd');
        let token = '';
        if (session) {
          token = session.getIdToken().getJwtToken();
          options = options || {};
          options.headers = options.headers || new Headers();
          options.headers.append('Authorization', token);
        }
        return this._http.get(url, options);
      });
    }
  </code></pre>
  
  <p><strong>API service's get function - Trail 2</strong></p>
  
  <pre><code>get(url: string, options?: RequestOptionsArgs): Observable&lt;Response&gt; {
  return this._authService.getSession().pipe(mergeMap((session) =&gt; {
    console.log('So what??');
    let token = '';
    if (session) {
      token = session.getIdToken().getJwtToken();
      options = options || {};
      options.headers = options.headers || new Headers();
      options.headers.append('Authorization', token);
    }
    return this._http.get(url, options);
  }));
  }
  </code></pre>
  
  <p><strong>Here how I am calling this api.</strong></p>
  
  <pre><code>getItemInfo(item) {
  return this._apiHttp.get('/assets/data/item.json')
    .map(res =&gt; {
      console.log(res);
      return res.json();
    })
    .subscribe(data =&gt; console.log(data),
       err =&gt; console.log(err), 
       () =&gt; console.log('done'));
  }
  </code></pre>
  
  <p>Now the problem is in both the cases console just prints.and not http call is being made.</p>
  
  <pre><code>Found Session
  done
  </code></pre>
  
  <p>I am not able understand where i am making mistake in using mergermap of switchmap in order to get the http request completed. </p>