title: silent sign in using oidc client with identity server 4
body: <p>I'm trying to implement silent login in oidc-client to use with Angular 2</p>
  
  <p>How can use oidc client to silently check if user is already logged in (idsvr4) and display the login details.</p>
  
  <p>the following code works, but i need to refresh the page</p>
  
  <p>idsvr 4 client</p>
  
  <pre><code>  // JavaScript Client
              new Client
              {
                  ClientId = "js",
                  ClientName = "JavaScript Client",
                  AllowedGrantTypes = GrantTypes.Implicit,
                  AllowAccessTokensViaBrowser = true,
  
  
                  RedirectUris = { "http://localhost:5002/callback.html" },
  
                  PostLogoutRedirectUris = { "http://localhost:5002/index.html" },
                  AllowedCorsOrigins = { "http://localhost:5002" },
  
                  AllowedScopes =
                  {
                      IdentityServerConstants.StandardScopes.OpenId,
                      IdentityServerConstants.StandardScopes.Profile,
                      "api1",
  
                  },
                      RequireConsent=false,
                  AllowOfflineAccess = true
              }
  </code></pre>
  
  <p>client side code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    var config = {
       authority: "http://localhost:5000",
      client_id: "js",
      redirect_uri: "http://localhost:5002/callback.html",
      silent_redirect_uri: "http://localhost:5002/callback.html",
      response_type: "id_token token",
      scope: "openid profile api1 offline_access",
      post_logout_redirect_uri: "http://localhost:5002/index.html",
  
  
  
      // Number of seconds before the token expires to trigger
      // the `tokenExpiring` event
      accessTokenExpiringNotificationTime: 4,
  
      // Do we want to renew the access token automatically when it's
      // about to expire?
      automaticSilentRenew: false,
     
      // Do we want to filter OIDC protocal-specific claims from the response?
      filterProtocolClaims: false,
  
      // use localStorage
      userStore: new Oidc.WebStorageStateStore({ store: window.localStorage })
      };
      var mgr = new Oidc.UserManager(config);
  
  
      // You can hook a logger to the library.
      // Conveniently, the methods exposed by the logger match
       // the `console` object
      Oidc.Log.logger = console;
  
      // When a user logs in successfully or a token is renewed, the `userLoaded`
      // event is fired. the `addUserLoaded` method allows to register a callback to
      // that event
      mgr.events.addUserLoaded(function (loadedUser) {
      console.log("$$$$$$$$$$$$$$$$$$$$$$$ added");
      });
  
      // Same mechanism for when the automatic renewal of a token fails
      mgr.events.addSilentRenewError(function (error) {
      console.error('$$$$$$$$$$$$$$$$$$$$$$$ error while renewing the access    token', error);
      });
  
      // When the automatic session management feature detects a change in
      // the user session state, the `userSignedOut` event is fired.
      mgr.events.addUserSignedOut(function () {
      alert('The user has signed out');
      });
  
      mgr.getUser().then(function (user) {
      if (user) {
          log("User logged in", user.profile);
      }
      else {
          log("User not logged in");
         // log("*****************************************************");
          mgr.signinSilent()
          .then(function (newUser) {
              console.log("doneeeeeeeeeeeeeeeeeeeee");
              console.log(newUser);
              console.log(newUser.profile);
          }).catch(function (e) {
              console.log("========  " + e);
          });;
          mgr.signinSilentCallback().then(function (newUser) {
          console.log("doneeeeeeeeeeeeeeeeeeeee");
          console.log(newUser);
          console.log(newUser.profile);
      }).catch(function (e) {
              console.log("&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;  "+e);
          });
  
      }
  
  
      });</code></pre>
  </div>
  </div>
  </p>
  
  <p>no user is getting returned in either methods of silentSignIn</p>
  
  <p>I want to get if user is logged in and retrieve the information as soon as the client is open.</p>
  
  <p>Or if there's a better way to do this in angular 2 then it's better.</p>