asp.net mvc - ASP .Net MVC and WCF Identity (Claims) Integration -


we're building platform client asp .net mvc one, using asp net identity 2.0 authentication , authorization (using claims), works great on web side.

we have wcf service allows crud operations on database (for multiple client applications), gets requests asp .net mvc client. want validate (authenticate & authorize) user before making specific crud actions in wcf side, need claims of user client, , perform validations (preferably in clean manner using headers or binding wcf able support matter).

i've been searching different forums no simple answer\tutorial specific scenario. can assist on matter?

thanks, nir.

i love this:

in iendpointbehavior implementation on client end:

public object beforesendrequest(ref message request, iclientchannel channel)     {         request.headers.add(messageheader.createheader("token", "http://myurl.com/service/token", _thetoken));         return null;     } 

then on service end add serviceauthenticationmanager

public override readonlycollection<iauthorizationpolicy> authenticate(         readonlycollection<iauthorizationpolicy> authpolicy, uri listenuri, ref message message)     {         iprincipal user = new myuserprincipal(null);          if(_currentservicecontracttype.getinterfaces()                                         .any(x => x == typeof(imysecuredservice)))         {             var tokenposition = message.headers.findheader("token", "http://myurl.com/service/token");              if (tokenposition >= 0 && tokenposition <= 5)             {                 var encryptedtoken = message.headers.getheader<string>(tokenposition);                  if (!string.isnullorwhitespace(encryptedtoken))                 {                     var serializedtoken = new myencryptionutility().decrypt(encryptedtoken);                     var token = mytokenserializer.deserialize(serializedtoken);                     var expire = new datetime(token.validtoticks);                     if (expire > datetime.now)                     {                         user = new myuserprincipal(token);                     }                 }             }            }         message.properties["principal"] = user;         thread.currentprincipal = user;         return authpolicy;     } 

this gives ability use built in claims or wif claims authentication. eitherway, simple. token created service , sent client (web) , stored in cookie. when there requests, token grabbed cookie , sent along service, where, inevitably can start adding permissions service side, versus doing them on web/mvc side, making cleaner code base using everyone's favorite friend, soa >= :)


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -