title: Secure Web API with token c#
body: <p>I created a mobile app with Cordova, with 2 Login methods Facebook and Google. I after I authenticate the token (FB or Google) I want to use one of them to secure my Web API 2 and communicate with my APP, but I don't know where to store it in the web API, I saved it to Thread.CurrentPrincipal but it returns null later.</p>
  
  <p>This is my code:</p>
  
  <pre><code>    public bool UserExist(Credentials credentials,ISQLDB socialDB,IEncrypt encrypt)
      {
          bool exist = false;
          //IPrincipal principal;
  
          if (credentials.fb_access_Token != "")
              exist =CheckFB(credentials.fb_access_Token);
          else if (credentials.Google_token != "")
              exist= CheckGoogle(credentials.Google_token);
  
          if(exist==true)
          {
              var identity = new GenericIdentity(credentials.Token);
              SetPrincipal(new GenericPrincipal(identity, null));
              return true;
          }
          else
              return false;
      }
  
      private void SetPrincipal(IPrincipal principal)
      {
          Thread.CurrentPrincipal = principal;
          if (HttpContext.Current != null)
          {
              HttpContext.Current.User = principal;
          }
  
      }
  </code></pre>
  
  <p>Web API secure is a complicated thing to me, I don't know why, so I appreciate your help. </p>