public ActionResult Index() { var userToken = ((IClaimsIdentity)Thread.CurrentPrincipal.Identity).BootstrapToken; var token = TokenHelper.GetSAML2ActAsTokenWithFunctionalAccount( actAsToken: userToken, user: "******", password: "******", usernamePasswordEndpoint: "https://REPLACE_WITH_ADFS/adfs/services/trust/13/usernamemixed", relyingParty: "REPLACE_WITH_RELYINGPARTY_IDENTIFIER"); var client = new Services.SampleServiceClient(); TokenHelper.AttachToken(client.ChannelFactory, token); try { client.DoWork(); ViewBag.Message = "Service was called"; } catch (SecurityAccessDeniedException ex) { ViewBag.Message = ex.Message; } return View(); }
static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback += delegate { return true; }; var client = new Services.SampleServiceClient(); Console.WriteLine("Press ENTER to call the service"); Console.ReadLine(); SecurityToken token = TokenHelper.GetSAML2TokenWithUserNameCredentials( user: "******", password: "******", usernamePasswordEndpoint: "https://<REPLACE_WITH_ADFS>/adfs/services/trust/13/usernamemixed", relyingPartyIdentifier: "REPLACE_WITH_RELYINGPARTY_IDENTIFIER"); Console.WriteLine("Getting token from ADFS..."); TokenHelper.AttachToken(client.ChannelFactory, token); try { Console.WriteLine("Calling service..."); client.DoWork(); } catch (SecurityAccessDeniedException ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Press ENTER to close"); Console.ReadLine(); }