简体   繁体   English

远程服务器返回错误:(401) 在 Zendesk 中未经授权

[英]The remote server returned an error: (401) Unauthorized in Zendesk

I have to access a page from the zendesk.com from my MVC application.我必须从我的 MVC 应用程序访问 zendesk.com 的页面。 I have username and authenticate ticket.我有用户名和验证票。 When I try to access that page it is returning the error "The remote server returned an error: (401) Unauthorized".当我尝试访问该页面时,它返回错误“远程服务器返回错误:(401) 未经授权”。 Here is the code for the authentication这是身份验证的代码

 string authTicket = "asdfsafdsafsdafdsafsf";       
 username = "user@mysite.com";
 string api_url = "https://mysite.zendesk.com/users/current.json";  
 string base64_creds = Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + authTicket));
 HttpWebRequest request = WebRequest.Create(api_url) as HttpWebRequest;
 request.Headers.Add("Authorization", "Basic " + base64_creds);
 using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
 {
      StreamReader reader = new StreamReader(response.GetResponseStream());
      string content = reader.ReadToEnd();
      //return Content(content);
      return View("https://mysite.zendesk.com/entries/mypage");
 }

Same sort of thing happened to me. 同样的事发生在我身上。 Unfortunately, my background is in the Zendesk API Ruby client, but I'll try to help out. 不幸的是,我的背景是在Zendesk API Ruby客户端,但我会尽力帮助。

It's not completely clear to me whether you're using token access with your API token or password access with a username/password combination, but it looks like you're using password access (if it's token access, then the colon format won't work). 我不完全清楚你是否使用带有用户名/密码组合的API令牌或密码访问的令牌访问,但看起来你正在使用密码访问(如果它是令牌访问,那么冒号格式不会工作)。 Double check the API docs and see whether the endpoint is only allowed for agents or end-users, and make sure the credentials you're providing match up with the required credentials. 仔细检查API文档,查看端点是否仅允许代理或最终用户使用,并确保您提供的凭据与所需的凭据相匹配。

Also, Log in to your Zendesk with an admin account and make sure you enabled token access if you're using a token, or password access if you're using your password. 此外,使用管理员帐户登录Zendesk,如果您正在使用令牌,请确保启用令牌访问权限,如果您使用密码,则确保密码访问权限。

Some of you will run into this issue when connecting to various Zendesk accounts around the place. 当你连接到各地的各种Zendesk帐户时,你们中的一些人会遇到这个问题。 Some percentage of Zendesk accounts have an IP whitelist setup, meaning that you can only make requests from explicitly allowed IP addresses or ranges. 有些百分比的Zendesk帐户具有IP白名单设置,这意味着您只能从明确允许的IP地址或范围发出请求。 There is no specific error message for a blocked IP, but it's something like "Can't authenticate you". 阻止的IP没有特定的错误消息,但它类似于“无法验证您”。

Not sure, but you might want to enable Zendesk API from Admin Center-> Apps and Integrations -> Zendesk API -> Settings (after enabling Zendesk API) -> Password Access .不确定,但您可能希望从Admin Center-> Apps and Integrations -> Zendesk API -> Settings (after enabling Zendesk API) -> Password Access I got error: 403 , and doing this solved the issue for me.我收到error: 403 ,这样做为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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