Saturday, 15 March 2014

c# - Put custom claims into security token and create it in ASP.NET Web API -


Is it possible to take certain custom claims, for example:

Find the given user pin Number and Device_ID, take the value for that user and put them in the claims.

  credentials DB DBTx = new credentials DB (); Var usr = dbctx.Credentials.Where (u = & gt; u.PIN == Model. Pin & amp; u.Device_Id == Model. Device_Id). SingleOrDefault (); Var identity = new claimability (); Identity.AddClaim (new claim ("username", usr.UserName)); Identity.AddClaim (new claim ("Device_Id", usr.Device_Id)); Identity.AddClaim (new claim ("Device_Name", usr.Device_Name)); Identity.AddClaim (new claim ("pin", usr.PIN.ToString ()));  

And make one of them a security token? How can this token be made, if we are not using some STS and how can consumers consume it later? Anyone have any ideas or good tutorials for sharing?

In this way I am doing this in my web API, where I am from database to user all I want to get the roles and add them one by one to my identity claims:

Introducing the user:

  IdentityUser user = new ApplicationDbContext () . Users.Where ([your conditions here ...]). FirstOrDefault (); Create Identity:  
  var ID = new claim object (references type authentication type);  

and using a loop to add roles for that identity claim:

  foreach (identity in user identerRole R.) {id. AddClaim (new claim (claim type roll, roles provider. Roll name.}  

Of course you use the same logic to add any information about that specific user Can you answer?


No comments:

Post a Comment