简体   繁体   中英

asp.net mvc 5 and oauth2 login

I'm working on a asp.net mvc 5 project that will use the meetup.com oauth2 api to login. Unfortunately, I'm having an issue where my webapp successfully redirects to the meetup login page and I can hit "allow", but then it will stop because the AuthenticationHandler detects the properties of the "state" field as null and nothing shows up on the page. I'm using passive AuthenticationMode and afaik meetup.com API doesn't use "state" field, so I'm not sure how to prevent the AuthenticationHandler from returning null and stopping in the middle because it thinks there's an error when there isn't a "state" to begin with. Here is the relevant code:

protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
    {
        AuthenticationProperties properties = null;

        try
        {
            string code = null;
            string state = null;

            IReadableStringCollection query = Request.Query;
            IList<string> values = query.GetValues("code");
            if (values != null && values.Count == 1)
            {
                code = values[0];
            }
            values = query.GetValues("state");
            if (values != null && values.Count == 1)
            {
                state = values[0];
            }

            properties = Options.StateDataFormat.Unprotect(state);
            if (properties == null)
            {
                return null; // the error here
            }

found a pre-existing open source library that works

https://github.com/KatanaContrib/KatanaContrib.Security.Meetup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM