Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle an Event and Store Claims into Cookie #2

Open
Engineerumair opened this issue Dec 12, 2018 · 3 comments
Open

Handle an Event and Store Claims into Cookie #2

Engineerumair opened this issue Dec 12, 2018 · 3 comments

Comments

@Engineerumair
Copy link

I need to capture event after successful authentication and store the claims into cookie, can you please guide on this

@Engineerumair
Copy link
Author

I have captured the event but I need to store the claims into cookie, can you please let me know how to store it

Here is my code

options.Events = new OpenIdConnectEvents()
{
OnUserInformationReceived = async n =>
{

                        // Exchange code for access and ID tokens
                        CookieOptions cookies = new CookieOptions();
                        cookies.Expires = DateTime.Now.AddDays(1);
                        cookies.IsEssential = true;
                        KeyValuePair<string, string> valuePair;
                        // write out the user claims
                        foreach (var claim in n.Principal.Claims)
                        {
                            if (claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")
                            {
                                valuePair = new KeyValuePair<string, string>("emailaddress", claim.Value);
                                n.HttpContext.Request.Cookies.Append(valuePair);         

                            }
                            else if (claim.Type == "name")
                            {
                                valuePair = new KeyValuePair<string, string>(claim.Type, claim.Value);
                                n.HttpContext.Request.Cookies.Append(valuePair);
                            }
                            
                        }
                    }
                    };


            });

@damienbod
Copy link
Owner

@Engineerumair slow to answer.. sorry.

Have you solved this?

Greetings Damien

@Engineerumair
Copy link
Author

Sorry, I was not able to store it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants