justintv / Twitch-API

A home for details about our API
www.twitch.tv
1.72k stars 381 forks source link

Chrome is canceling request to Auth Page #530

Closed nfMalde closed 8 years ago

nfMalde commented 8 years ago

Hi Im testing arround at the moment with the Twitch API.

Im Testing on: .NET MVC 5, Localhost. I tryed to redirect the user to https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=....&redirect_uri=http://localhost:63477/ExternalConnections/Twitch/Authorize&scope=user_read+channel_read&state=...

Somehow the request is getting canceled by chrome. Firefox is working. Is there something wrong in my call or why is only chrome canceling the request?

Here is a screenshot from the network tab: twitchrequest

3ventic commented 8 years ago

Not sure if related, but you should URL encode the redirect_uri value.

nfMalde commented 8 years ago

Done. I also removed all parameters except client_id and response_type. Request is still cancelled.

Here is the code where im redirecting:

       if(Session["twitch.state"] != null)
        {
            Session.Remove("twitch.state");
        }
        Session.Add("twitch.state", "request" + Guid.NewGuid().ToString().ToLower());
        string url = "https://api.twitch.tv/kraken/oauth2/authorize?response_type=code"
                        + "&client_id={0}"
                        + "&redirect_uri={1}"
                        + "&scope={2}"
                        + "&state={3}";

        string absUrl = new System.UriBuilder(Request.Url.AbsoluteUri)
        {
            Path = Url.Action("Authorize"),
            Query = "redirect_to="+ HttpUtility.UrlEncode( redirect_to),
        }.Uri.ToString();

            url = String.Format(url,
                HttpUtility.UrlEncode(ConfigurationManager.AppSettings["twitch.clientID"]),
                HttpUtility.UrlEncode(absUrl),
                HttpUtility.UrlEncode("user_read channel_read"),
                HttpUtility.UrlEncode(Session["twitch.state"].ToString())
                );

            return Redirect(url); 
DallasNChains commented 8 years ago

If this isn't resolved, I would re-ask in the Twitch Developer Forums.