what i'm trying accessing user claims returns adfs login. adfs returns username , username have run query db user information , store it. don't know , best practice is. can access user claims in view controller like:
public actionresult index() { var ctx = request.getowincontext(); claimsprincipal user = ctx.authentication.user; ienumerable<claim> claims = user.claims; return view(); }
but need said access claims in global.asax.cs or startup.cs store user information before application runs.
this startup.auth.cs file:
public partial class startup { private static string realm = configurationmanager.appsettings["ida:wtrealm"]; private static string adfsmetadata = configurationmanager.appsettings["ida:adfsmetadata"]; public void configureauth(iappbuilder app) { app.setdefaultsigninasauthenticationtype(wsfederationauthenticationdefaults.authenticationtype); app.usecookieauthentication( new cookieauthenticationoptions { authenticationtype = wsfederationauthenticationdefaults.authenticationtype }); app.usewsfederationauthentication( new wsfederationauthenticationoptions { wtrealm = realm, metadataaddress = adfsmetadata }); } }
we add event handler wsfederationauthenticationoptions
value in our startup file.
this happens after security token has been validated.
app.usewsfederationauthentication(new wsfederationauthenticationoptions() { metadataaddress = metadataaddress, wtrealm = wtrealm, wreply = callbackpath, notifications = new wsfederationauthenticationnotifications() { securitytokenvalidated = (ctx) => { claimsidentity identity = ctx.authenticationticket.identity; dosomethingwithloggedinuser(identity); } } };
Comments
Post a Comment