Can't set cookie events
See original GitHub issueWhich Version of Microsoft Identity Web are you using ? Note that to get help, you need to run the latest version. 0.1.2-preview
Where is the issue?
- Web App
- Sign-in users
- Sign-in users and call web APIs
- Web API
- Protected web APIs (Validating tokens)
- Protected web APIs (Validating scopes)
- Protected web APIs call downstream web APIs
- Token cache serialization
- In Memory caches
- Session caches
- Distributed caches
Other? - please describe;
Is this a new or existing app?
I’m attempting to upgrade an existing app that uses MicrosoftAccount API (i.e. AddMicrosoftAccount()). I’ve repro’d the issue in the sample 2-1-Call-MSGraph.
Repro
Add this code in ConfigureServices before AddSignIn():
services.ConfigureApplicationCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromHours(1);
// TODO: MAKE COOKIE EXPIRE BEFORE ACCESS TOKEN
options.Events = new CookieAuthenticationEvents
{
OnSigningIn = async (context) =>
{
var identity = context.Principal.Identity as ClaimsIdentity;
var userId = context.Principal.Claims.FirstOrDefault(claim => claim.Type == "preferred_username" || claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")?.Value;
}
};
});
services.AddSignIn(Configuration);
Expected behavior The OnSigningIn delegate should be called when a user logs in…
Actual behavior In this case, the delegate is never called. If I use AddCookie() (as with MicrosoftAccount API), an exception “Scheme already exists: Cookies” is thrown at startup.
Additional context/ Logs / Screenshots dotnet.txt
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
google chrome - Cannot set cookies in Javascript
Recently I stumbled upon a similar issue. My script couldn't store a cookie in Chromium, although it worked well on all other major...
Read more >Set-Cookie - HTTP - MDN Web Docs
The Set-Cookie HTTP response header is used to send a cookie from the server to the user agent, so that the user agent...
Read more >javascript - Why can't I set a cookie? [SOLVED]
Your function is called "setCookie" but you are calling "createCookie" in your onclick event. Change either the function name or the call so ......
Read more >Cookies, document.cookie
A domain defines where the cookie is accessible. In practice though, there are limitations. We can't set any domain. There's no way to...
Read more >Can't find cookie for validation in EventSubscriber
2 Answers. Some ideas: Like for the config you have to add a cache dependency for the cookie, too: $response->getCacheableMetadata()-> ...
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 FreeTop 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
Top GitHub Comments
Yes, it works! Thanks, I appreciate the support!
Yes sorry I wasn’t clear about that. Below is the complete function. The only other changes I have made are to appsettings.json to use my AAD info.
So you are seeing the callback get called?