Search code examples
zendesk-api

Zendesk OAuth "Invalid Authorization Request"


I'm trying to implement Zendesk integration via OAuth 2.0. When I redirect to the login page i get error: "Invalid Authorization Request" and "bad request".

My redirect url:

            string redirectUrl = $"https://{subdomain}.zendesk.com/oauth/authorizations/new?response_type=code&redirect_uri={redirectUri}&client_id={client_id}&scope=read";

Solution

  • It is probably related to the redirect url. It seems that Zendesk requires the redirect url to be exacly the same as url from which you redirected to the Zendesk. In ASP .NET Core WebApi it can be solved by using one api method for both redirecting to Zendesk and receiving redirect from. Like this:

    [Route("[action]")]
        public IActionResult Authorize()
        {
            if (!Request.Query.ContainsKey("code"))
            {
                string redirectUrl = $"https://{subdomain}.zendesk.com/oauth/authorizations/new?response_type=code&redirect_uri={redirectUri}&client_id={client_id}&scope=read";
                return Redirect(redirectUrl);
            }
            else
            {
                var code = Request.Query["code"];
                //your code here
            }
    
        }