question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cookie Auth Fails in Embedded App

See original GitHub issue

I am creating an app using .NET Core 2.1

When the app loads in the iFrame, the auth cookie is never set or read. Auth works fine outside of the iFrame. What am I missing?

I am running ngrok using: ngrok http -subdomain=mydomain -host-header=localhost:62754 62754

Here is my AuthorizationHandler.HandleRequirementAsync method 👍

protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
      SubscribedRequirment requirement) {
      // Get the context       
      if (!(context.Resource is AuthorizationFilterContext redirectContext)) {
        context.Fail();
        return Task.CompletedTask;
      }
      var isAuthenticated = _signInManager.IsSignedIn(context.User); // <-- This is always false in embedded iFrame
      if (isAuthenticated) {
        var userId = context.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; 
        //Get the shop's status from the CacheEngine.
        var status = _cacheEngine.GetShopStatus(userId);
        if (status.BillingIsConnected && status.ShopIsConnected) {
          context.Succeed(requirement);
          return Task.CompletedTask;
        }
        if (status.BillingIsConnected == false) {
          //User has connected their Shopify shop, but they haven't accepted a subscription charge.
          redirectContext.Result = new RedirectToActionResult("register", "charge", null);
          context.Succeed(requirement);
          return Task.CompletedTask;
        }
        //User has created an account, but they haven't connected their Shopify shop.
        redirectContext.Result = new RedirectToActionResult("register", "connect", null);
        context.Succeed(requirement);
        return Task.CompletedTask;
      }
      //User has created an account, but they haven't connected their Shopify shop.
      redirectContext.Result = new RedirectToActionResult("index", "home", null);
      context.Succeed(requirement);
      return Task.CompletedTask;
    }

In Start up

services.Configure<CookiePolicyOptions>(options =>
      {
        options.CheckConsentNeeded = context => false;
        options.MinimumSameSitePolicy = SameSiteMode.None;
      });

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
elegaultcommented, Mar 6, 2021

This post solved a major headache for me. THANK YOU!

1reaction
Matt-Kaminskicommented, Apr 1, 2020

Which version of .Net are you using?

I’ve had this problem with .NET Core 2.1. It turns out that there is a bug caused by SameSiteMode.None not sending any attribute. For me, this was the solution:

Does not work:

myCookie.Path = “/”; myCookie.SameSite = SameSiteMode.None;

Do work:

myCookie.Path = “/; SameSite=None”;

Source: https://stackoverflow.com/a/58817862/4590784

Read more comments on GitHub >

github_iconTop Results From Across the Web

Embedded app cookie blocked
I have a not negligible info: This is only occuring when I set the application url to the Heroku endpoint. When serving the...
Read more >
Cookie not being set in iframe
I have an Identity Server (v4) on one server and a web application on a different server & domain. I only need windows...
Read more >
Connected Apps Authentication Fails in Safari on iOS
Configure the Safari browser to allow third-party cookies, and then use Safari to access the embedded view. For instructions on how to enable ......
Read more >
Embedded browser for SAML authentication does not pop ...
The embedded browser for SAML authentication was not displayed on attempts of connection to the gateway after cookie expiration.
Read more >
Embedded Content or Authentication Isn't Working between ...
If the authentication fails when using an OSLC Connect application and trying to connect to a remote OSLC application, it means you must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found