Skip to main content

排查 OAuth 应用访问令牌请求错误

为访问令牌交换代码时,可能会发生另外一组错误。 这些响应的格式由您传递的接受标头确定。

注意:这些示例仅显示 JSON 响应。

客户端凭据不正确

如果你传递的客户端_ID 和/或客户端_密码不正确,将收到此错误响应。

{
  "error": "incorrect_client_credentials",
  "error_description": "The client_id and/or client_secret passed are incorrect.",
  "error_uri": "/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#incorrect-client-credentials"
}

要解决此错误,请确保您拥有 OAuth app 的正确凭据。 仔细检查 client_idclient_secret,并确保它们正确无误,并将其正确传递给 GitHub。

重定向 URI 不匹配

如果你提供的 redirect_uri 与你在 OAuth app 中注册的 URL 不匹配,将收到此错误消息:

{
  "error": "redirect_uri_mismatch",
  "error_description": "The redirect_uri MUST match the registered callback URL for this application.",
  "error_uri": "/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch2"
}

要更正此错误,请提供一个与你注册的 URL 匹配的 redirect_uri,或者忽略此参数以使用在应用程序中注册的默认 URL。

验证码错误

如果你传递的验证码不正确、已过期或与你在第一次授权请求中收到的验证码不匹配,将收到此错误。

{
  "error": "bad_verification_code",
  "error_description": "The code passed is incorrect or expired.",
  "error_uri": "/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#bad-verification-code"
}

若要解决此错误,请再次启动 OAuth 授权过程,并获取新代码。

未经验证的用户电子邮件

如果你尝试为其生成用户访问令牌的用户尚未向 GitHub 验证其主要电子邮件地址,则会收到此错误。

{
  "error": "unverified_user_email",
  "error_description": "The user must have a verified primary email.",
  "error_uri": "/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#unverified_user_email"
}

若要解决此错误,请提示用户验证在 GitHub 帐户上验证其主要电子邮件地址。 有关详细信息,请参阅 “验证电子邮件地址”。