Sustainsys SAML2 Sample for ASP.NET Core WebAPI without Identity2019 Community Moderator Electionhow to implement google login in .net core without an entityframework providerasp.net core 1.0 get windows identity in webapiASP.NET Core WebAPI default route not workingAsp.Net WebApi Core 2.0 Identity With JWTBearer Without cookiesIdentity server 4 with SAML 2.0 as external identity provider for SSOASP.NET Core (2.1) Web API: Identity and external login providerUsing ASP.Net Core 2.0 Identity Login Application to Authenticate an ASP.Net MVC Web ApplicationCan I configure ReturnUrl on logout in sustainsys-saml2?Can I limit the amount of claims received in my SP?SP-Initiated SLO Generating multiple SLO requestsHow to use Sustainsys.Saml2.AspNetCore2 in existing net core app?

Plausibility of Mushroom Buildings

How to resolve: Reviewer #1 says remove section X vs. Reviewer #2 says expand section X

Would an aboleth's Phantasmal Force lair action be affected by Counterspell, Dispel Magic, and/or Slow?

Rationale to prefer local variables over instance variables?

Expressing logarithmic equations without logs

How can I manipulate the output of Information?

What will happen if my luggage gets delayed?

Can the alpha, lambda values of a glmnet object output determine whether ridge or Lasso?

Should I take out a loan for a friend to invest on my behalf?

Does Christianity allow for believing on someone else's behalf?

What would be the most expensive material to an intergalactic society?

How do we create new idioms and use them in a novel?

Why is gluten-free baking possible?

How can I find out information about a service?

What can I do if someone tampers with my SSH public key?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Confusion about Complex Continued Fraction

Why does cron require MTA for logging?

What materials can be used to make a humanoid skin warm?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Can't make sense of a paragraph from Lovecraft

Vocabulary for giving just numbers, not a full answer

Signed and unsigned numbers

Is it possible that a question has only two answers?



Sustainsys SAML2 Sample for ASP.NET Core WebAPI without Identity



2019 Community Moderator Electionhow to implement google login in .net core without an entityframework providerasp.net core 1.0 get windows identity in webapiASP.NET Core WebAPI default route not workingAsp.Net WebApi Core 2.0 Identity With JWTBearer Without cookiesIdentity server 4 with SAML 2.0 as external identity provider for SSOASP.NET Core (2.1) Web API: Identity and external login providerUsing ASP.Net Core 2.0 Identity Login Application to Authenticate an ASP.Net MVC Web ApplicationCan I configure ReturnUrl on logout in sustainsys-saml2?Can I limit the amount of claims received in my SP?SP-Initiated SLO Generating multiple SLO requestsHow to use Sustainsys.Saml2.AspNetCore2 in existing net core app?










0















Does anyone have a working sample for Sustainsys Saml2 library for ASP.NET Core WebAPI only project (no Mvc) and what's more important without ASP Identity? The sample provided on github strongly relies on MVC and SignInManager which I do not need nor want to use.



I added Saml2 authentication and at first it worked fine with my IdP (I also checked the StubIdP provided by Sustainsys) for first few steps so:



  • IdP metadata get properly loaded

  • My API properly redirects to sign-in page

  • Sign-in page redirects to /Saml2/Acs page, and I see in the logs that it parses the result successfully

However I don't know how to move forward from there and extract user login and additional claims (my IdP provided also an e-mail, and it is included in SAML response which I confirmed in the logs).



Following some samples found on the web and modyfing a little bit the MVC Sample from GitHub I did the following:



In Startup.cs:



...
.AddSaml2(Saml2Defaults.Scheme,
options =>

options.SPOptions.EntityId = new EntityId("...");
options.SPOptions.ServiceCertificates.Add(...));
options.SPOptions.Logger = new SerilogSaml2Adapter();
options.SPOptions.ReturnUrl = new Uri(Culture.Invariant($"https://localhost:44364/Account/Callback?returnUrl=%2F"));

var idp =
new IdentityProvider(new EntityId("..."), options.SPOptions)

LoadMetadata = true,
AllowUnsolicitedAuthnResponse = true, // At first /Saml2/Acs page throwed an exception that response was unsolicited so I set it to true
MetadataLocation = "...",
SingleSignOnServiceUrl = new Uri("...") // I need to set it explicitly because my IdP returns different url in the metadata
;
options.IdentityProviders.Add(idp);
);


In AccountContoller.cs (I tried to follow a somewhat similar situation described at how to implement google login in .net core without an entityframework provider):



[Route("[controller]")]
[ApiController]
public class AccountController : ControllerBase
{
private readonly ILog _log;

public AccountController(ILog log)

_log = log;


[HttpGet("Login")]
[AllowAnonymous]
public IActionResult Login(string returnUrl)

return new ChallengeResult(
Saml2Defaults.Scheme,
new AuthenticationProperties

// It looks like this parameter is ignored, so I set ReturnUrl in Startup.cs
RedirectUri = Url.Action(nameof(LoginCallback), new returnUrl )
);


[HttpGet("Callback")]
[AllowAnonymous]
public async Task<IActionResult> LoginCallback(string returnUrl)


var authenticateResult = await HttpContext.AuthenticateAsync(Constants.Auth.Schema.External);

_log.Information("Authenticate result: @authenticateResult", authenticateResult);

// I get false here and no information on claims etc.
if (!authenticateResult.Succeeded)

return Unauthorized();


// HttpContext.User does not contain any data either


// code below is not executed
var claimsIdentity = new ClaimsIdentity(Constants.Auth.Schema.Application);
claimsIdentity.AddClaim(authenticateResult.Principal.FindFirst(ClaimTypes.NameIdentifier));

_log.Information("Logged in user with following claims: @Claims", authenticateResult.Principal.Claims);

await HttpContext.SignInAsync(Constants.Auth.Schema.Application, new ClaimsPrincipal(claimsIdentity));

return LocalRedirect(returnUrl);



TLDR: Configuration for SAML in my ASP.NET Core WebApi project looks fine, and I get success response with proper claims which I checked in the logs. I do not know how to extract this data (either return url is wrong or my callback method should work differently). Also, it is puzzling why successfuly redirect from SSO Sign-In page is treated as "unsolicited", maybe this is the problem?



Thanks for any assistance










share|improve this question









New contributor




LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    0















    Does anyone have a working sample for Sustainsys Saml2 library for ASP.NET Core WebAPI only project (no Mvc) and what's more important without ASP Identity? The sample provided on github strongly relies on MVC and SignInManager which I do not need nor want to use.



    I added Saml2 authentication and at first it worked fine with my IdP (I also checked the StubIdP provided by Sustainsys) for first few steps so:



    • IdP metadata get properly loaded

    • My API properly redirects to sign-in page

    • Sign-in page redirects to /Saml2/Acs page, and I see in the logs that it parses the result successfully

    However I don't know how to move forward from there and extract user login and additional claims (my IdP provided also an e-mail, and it is included in SAML response which I confirmed in the logs).



    Following some samples found on the web and modyfing a little bit the MVC Sample from GitHub I did the following:



    In Startup.cs:



    ...
    .AddSaml2(Saml2Defaults.Scheme,
    options =>

    options.SPOptions.EntityId = new EntityId("...");
    options.SPOptions.ServiceCertificates.Add(...));
    options.SPOptions.Logger = new SerilogSaml2Adapter();
    options.SPOptions.ReturnUrl = new Uri(Culture.Invariant($"https://localhost:44364/Account/Callback?returnUrl=%2F"));

    var idp =
    new IdentityProvider(new EntityId("..."), options.SPOptions)

    LoadMetadata = true,
    AllowUnsolicitedAuthnResponse = true, // At first /Saml2/Acs page throwed an exception that response was unsolicited so I set it to true
    MetadataLocation = "...",
    SingleSignOnServiceUrl = new Uri("...") // I need to set it explicitly because my IdP returns different url in the metadata
    ;
    options.IdentityProviders.Add(idp);
    );


    In AccountContoller.cs (I tried to follow a somewhat similar situation described at how to implement google login in .net core without an entityframework provider):



    [Route("[controller]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
    private readonly ILog _log;

    public AccountController(ILog log)

    _log = log;


    [HttpGet("Login")]
    [AllowAnonymous]
    public IActionResult Login(string returnUrl)

    return new ChallengeResult(
    Saml2Defaults.Scheme,
    new AuthenticationProperties

    // It looks like this parameter is ignored, so I set ReturnUrl in Startup.cs
    RedirectUri = Url.Action(nameof(LoginCallback), new returnUrl )
    );


    [HttpGet("Callback")]
    [AllowAnonymous]
    public async Task<IActionResult> LoginCallback(string returnUrl)


    var authenticateResult = await HttpContext.AuthenticateAsync(Constants.Auth.Schema.External);

    _log.Information("Authenticate result: @authenticateResult", authenticateResult);

    // I get false here and no information on claims etc.
    if (!authenticateResult.Succeeded)

    return Unauthorized();


    // HttpContext.User does not contain any data either


    // code below is not executed
    var claimsIdentity = new ClaimsIdentity(Constants.Auth.Schema.Application);
    claimsIdentity.AddClaim(authenticateResult.Principal.FindFirst(ClaimTypes.NameIdentifier));

    _log.Information("Logged in user with following claims: @Claims", authenticateResult.Principal.Claims);

    await HttpContext.SignInAsync(Constants.Auth.Schema.Application, new ClaimsPrincipal(claimsIdentity));

    return LocalRedirect(returnUrl);



    TLDR: Configuration for SAML in my ASP.NET Core WebApi project looks fine, and I get success response with proper claims which I checked in the logs. I do not know how to extract this data (either return url is wrong or my callback method should work differently). Also, it is puzzling why successfuly redirect from SSO Sign-In page is treated as "unsolicited", maybe this is the problem?



    Thanks for any assistance










    share|improve this question









    New contributor




    LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      Does anyone have a working sample for Sustainsys Saml2 library for ASP.NET Core WebAPI only project (no Mvc) and what's more important without ASP Identity? The sample provided on github strongly relies on MVC and SignInManager which I do not need nor want to use.



      I added Saml2 authentication and at first it worked fine with my IdP (I also checked the StubIdP provided by Sustainsys) for first few steps so:



      • IdP metadata get properly loaded

      • My API properly redirects to sign-in page

      • Sign-in page redirects to /Saml2/Acs page, and I see in the logs that it parses the result successfully

      However I don't know how to move forward from there and extract user login and additional claims (my IdP provided also an e-mail, and it is included in SAML response which I confirmed in the logs).



      Following some samples found on the web and modyfing a little bit the MVC Sample from GitHub I did the following:



      In Startup.cs:



      ...
      .AddSaml2(Saml2Defaults.Scheme,
      options =>

      options.SPOptions.EntityId = new EntityId("...");
      options.SPOptions.ServiceCertificates.Add(...));
      options.SPOptions.Logger = new SerilogSaml2Adapter();
      options.SPOptions.ReturnUrl = new Uri(Culture.Invariant($"https://localhost:44364/Account/Callback?returnUrl=%2F"));

      var idp =
      new IdentityProvider(new EntityId("..."), options.SPOptions)

      LoadMetadata = true,
      AllowUnsolicitedAuthnResponse = true, // At first /Saml2/Acs page throwed an exception that response was unsolicited so I set it to true
      MetadataLocation = "...",
      SingleSignOnServiceUrl = new Uri("...") // I need to set it explicitly because my IdP returns different url in the metadata
      ;
      options.IdentityProviders.Add(idp);
      );


      In AccountContoller.cs (I tried to follow a somewhat similar situation described at how to implement google login in .net core without an entityframework provider):



      [Route("[controller]")]
      [ApiController]
      public class AccountController : ControllerBase
      {
      private readonly ILog _log;

      public AccountController(ILog log)

      _log = log;


      [HttpGet("Login")]
      [AllowAnonymous]
      public IActionResult Login(string returnUrl)

      return new ChallengeResult(
      Saml2Defaults.Scheme,
      new AuthenticationProperties

      // It looks like this parameter is ignored, so I set ReturnUrl in Startup.cs
      RedirectUri = Url.Action(nameof(LoginCallback), new returnUrl )
      );


      [HttpGet("Callback")]
      [AllowAnonymous]
      public async Task<IActionResult> LoginCallback(string returnUrl)


      var authenticateResult = await HttpContext.AuthenticateAsync(Constants.Auth.Schema.External);

      _log.Information("Authenticate result: @authenticateResult", authenticateResult);

      // I get false here and no information on claims etc.
      if (!authenticateResult.Succeeded)

      return Unauthorized();


      // HttpContext.User does not contain any data either


      // code below is not executed
      var claimsIdentity = new ClaimsIdentity(Constants.Auth.Schema.Application);
      claimsIdentity.AddClaim(authenticateResult.Principal.FindFirst(ClaimTypes.NameIdentifier));

      _log.Information("Logged in user with following claims: @Claims", authenticateResult.Principal.Claims);

      await HttpContext.SignInAsync(Constants.Auth.Schema.Application, new ClaimsPrincipal(claimsIdentity));

      return LocalRedirect(returnUrl);



      TLDR: Configuration for SAML in my ASP.NET Core WebApi project looks fine, and I get success response with proper claims which I checked in the logs. I do not know how to extract this data (either return url is wrong or my callback method should work differently). Also, it is puzzling why successfuly redirect from SSO Sign-In page is treated as "unsolicited", maybe this is the problem?



      Thanks for any assistance










      share|improve this question









      New contributor




      LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      Does anyone have a working sample for Sustainsys Saml2 library for ASP.NET Core WebAPI only project (no Mvc) and what's more important without ASP Identity? The sample provided on github strongly relies on MVC and SignInManager which I do not need nor want to use.



      I added Saml2 authentication and at first it worked fine with my IdP (I also checked the StubIdP provided by Sustainsys) for first few steps so:



      • IdP metadata get properly loaded

      • My API properly redirects to sign-in page

      • Sign-in page redirects to /Saml2/Acs page, and I see in the logs that it parses the result successfully

      However I don't know how to move forward from there and extract user login and additional claims (my IdP provided also an e-mail, and it is included in SAML response which I confirmed in the logs).



      Following some samples found on the web and modyfing a little bit the MVC Sample from GitHub I did the following:



      In Startup.cs:



      ...
      .AddSaml2(Saml2Defaults.Scheme,
      options =>

      options.SPOptions.EntityId = new EntityId("...");
      options.SPOptions.ServiceCertificates.Add(...));
      options.SPOptions.Logger = new SerilogSaml2Adapter();
      options.SPOptions.ReturnUrl = new Uri(Culture.Invariant($"https://localhost:44364/Account/Callback?returnUrl=%2F"));

      var idp =
      new IdentityProvider(new EntityId("..."), options.SPOptions)

      LoadMetadata = true,
      AllowUnsolicitedAuthnResponse = true, // At first /Saml2/Acs page throwed an exception that response was unsolicited so I set it to true
      MetadataLocation = "...",
      SingleSignOnServiceUrl = new Uri("...") // I need to set it explicitly because my IdP returns different url in the metadata
      ;
      options.IdentityProviders.Add(idp);
      );


      In AccountContoller.cs (I tried to follow a somewhat similar situation described at how to implement google login in .net core without an entityframework provider):



      [Route("[controller]")]
      [ApiController]
      public class AccountController : ControllerBase
      {
      private readonly ILog _log;

      public AccountController(ILog log)

      _log = log;


      [HttpGet("Login")]
      [AllowAnonymous]
      public IActionResult Login(string returnUrl)

      return new ChallengeResult(
      Saml2Defaults.Scheme,
      new AuthenticationProperties

      // It looks like this parameter is ignored, so I set ReturnUrl in Startup.cs
      RedirectUri = Url.Action(nameof(LoginCallback), new returnUrl )
      );


      [HttpGet("Callback")]
      [AllowAnonymous]
      public async Task<IActionResult> LoginCallback(string returnUrl)


      var authenticateResult = await HttpContext.AuthenticateAsync(Constants.Auth.Schema.External);

      _log.Information("Authenticate result: @authenticateResult", authenticateResult);

      // I get false here and no information on claims etc.
      if (!authenticateResult.Succeeded)

      return Unauthorized();


      // HttpContext.User does not contain any data either


      // code below is not executed
      var claimsIdentity = new ClaimsIdentity(Constants.Auth.Schema.Application);
      claimsIdentity.AddClaim(authenticateResult.Principal.FindFirst(ClaimTypes.NameIdentifier));

      _log.Information("Logged in user with following claims: @Claims", authenticateResult.Principal.Claims);

      await HttpContext.SignInAsync(Constants.Auth.Schema.Application, new ClaimsPrincipal(claimsIdentity));

      return LocalRedirect(returnUrl);



      TLDR: Configuration for SAML in my ASP.NET Core WebApi project looks fine, and I get success response with proper claims which I checked in the logs. I do not know how to extract this data (either return url is wrong or my callback method should work differently). Also, it is puzzling why successfuly redirect from SSO Sign-In page is treated as "unsolicited", maybe this is the problem?



      Thanks for any assistance







      asp.net-core asp.net-core-webapi sustainsys-saml2






      share|improve this question









      New contributor




      LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Mar 7 at 8:39







      LizardErrtu













      New contributor




      LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Mar 6 at 14:23









      LizardErrtuLizardErrtu

      12




      12




      New contributor




      LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      LizardErrtu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          LizardErrtu is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025336%2fsustainsys-saml2-sample-for-asp-net-core-webapi-without-identity%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          LizardErrtu is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          LizardErrtu is a new contributor. Be nice, and check out our Code of Conduct.












          LizardErrtu is a new contributor. Be nice, and check out our Code of Conduct.











          LizardErrtu is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025336%2fsustainsys-saml2-sample-for-asp-net-core-webapi-without-identity%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved