public static async Task <ClaimsIdentity> GetIdentityFromExternalProvider(this IOwinContext context) { if (context == null) { throw new ArgumentNullException("context"); } var id = await context.GetIdentityFromExternalSignIn(); if (id != null) { // this is mapping from the external IdP's issuer to the name of the // katana middleware that's registered in startup var result = await context.GetAuthenticationFrom(Constants.ExternalAuthenticationType); if (!result.Properties.Dictionary.Keys.Contains(Constants.Authentication.KatanaAuthenticationType)) { throw new InvalidOperationException("Missing KatanaAuthenticationType"); } var provider = result.Properties.Dictionary[Constants.Authentication.KatanaAuthenticationType]; var newClaims = id.Claims.Select(x => new Claim(x.Type, x.Value, x.ValueType, provider)); id = new ClaimsIdentity(newClaims, id.AuthenticationType); } return(id); }