Cookie Auth Fails in Embedded App
See original GitHub issueI 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:
- Created 5 years ago
- Comments:16 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This post solved a major headache for me. THANK YOU!
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:
Do work:
Source: https://stackoverflow.com/a/58817862/4590784