首页 > 解决方案 > YouTube 授权码交换失败并出现 redirect_uri_mismatch

问题描述

我正在尝试将授权代码交换为访问代码,但我收到一条错误消息“ redirect_uri_mismatch ”。

我等了大约 8 个小时以防它需要更新,但到目前为止还没有运气。

重定向 uri 设置正确,正如您从此处的图像中看到的那样。

初始前端重定向/请求:

GET => https://accounts.google.com/o/oauth2/v2/auth
    ?scope=https://www.googleapis.com/auth/youtube.readonly
    &include_granted_scopes=true
    &state=state_parameter_passthrough_value
    &redirect_uri=http://localhost:4200/profile?platform=youtube
    &access_type=offline
    &response_type=code
    &client_id=[HIDDEN]

解析代码后,我将代码交换为访问代码:

POST => https://oauth2.googleapis.com/token
    ?client_id=[HIDDEN]
    &client_secret=[HIDDEN]
    &code=[HIDDEN]
    &grant_type=authorization_code
    &redirect_uri=http://localhost:2222/youtube/oauth

回复:

data: {
  error: 'redirect_uri_mismatch',
  error_description: 'Bad Request'
}

标签: oauthyoutubegoogle-oauth

解决方案


显然,redirect_uri 必须与初始请求的 uri 匹配。问题已解决,请随时为可见性投票 - 谢谢。

来源:https ://www.rfc-editor.org/rfc/rfc6749#section-4.1.3


推荐阅读