MVC save a token in session

前端 未结 4 1676
我寻月下人不归
我寻月下人不归 2021-01-14 01:22

I am calling a service, and I need to pass the user\'s permanent security token with every request I make.

In order to do that, I\'ve added this method to my base

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 02:14

    If User.Identity outlasts the Session, why not store the token as a Claim in the Identity? Something like:

    var claims = new[]
    {
        new Claim("access_token", string.Format("Bearer {0}", token)),
    };
    
    var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
    
    Request.GetOwinContext().Authentication.SignIn(options, identity);
    

提交回复
热议问题