无法使用访问令牌交换身份验证令牌 - 重定向 uri 不匹配
unable to exchange auth token with access token - redirect uri missmatch
我尝试在下面构建:
通过以下步骤:this 个步骤
然而,当我尝试将授权代码(由我的移动应用程序提供)交换到 google 服务器时,我一直收到重定向 uri 不匹配 - 我无法理解,因为从技术上讲,不需要重定向 uri我的流程案例...
详情如下:
在 Android 客户端:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
.requestServerAuthCode(serverClientId, false)
.build();
/**** bla.... ****/
GoogleSignInAccount acct = result.getSignInAccount();
String authCode = acct.getServerAuthCode();
/**** android app will send this authCode to my server ****/
/**** sample authCode: 4/Jny2Mxxx3x09sy4pqY3ZAwSTEz8rw2xxxxC-4VxxxxM
在我的后端服务器中:
try:
# i receive authCode correctly from android app.
# and use authCode to exchange to Access Token to google server as below:
credentials = client.credentials_from_clientsecrets_and_code(
app.config.get('GG_APP_SECRET'),
['https://www.googleapis.com/auth/plus.me', 'profile', 'email'],
authCode)
except Exception as e:
log.info('>>>>> I always receive: redirect uri missmatch here: %s <<<<<', e)
return generate_response(code=400, error=False, type='Fail', message=str(e))
这是来自我的后端服务器的 curl:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"authCode": "4/HP_cP_t70pgBrxxx7sjzCil7kaUHkxxxerdkMxxxrRg" \
}' 'http://localhost:5005/api/user/register/gg'
这是我的控制台设置:
问题:
android客户端中的serverClientId应该是上图的clientID吗?
我应该在上面的 google 控制台中输入的重定向 uri 是什么?
我应该 set/configure 我的重定向 uri 是什么?或者我需要做任何特定的设置吗?
好的,我去,
如果你看到 this
你会发现:
def credentials_from_clientsecrets_and_code(filename, scope, code,
message=None,
redirect_uri='postmessage',
http=None,
cache=None,
device_uri=None):
你意识到 redirect_uri = 'postmessage' 在我的情况下我没有 post 消息。
所以我要做的是将 redirect_uri
与我在 google 控制台
中的 authorize redirect uri
相匹配
所以对于我上面问题中的情况,我将 python 代码更改为:
credentials = client.credentials_from_clientsecrets_and_code(
app.config.get('GG_APP_SECRET'),
['https://www.googleapis.com/auth/plus.me', 'profile', 'email'],
authCode, redirect_uri='https://developers.google.com/oauthplayground')
我尝试在下面构建:
通过以下步骤:this 个步骤
然而,当我尝试将授权代码(由我的移动应用程序提供)交换到 google 服务器时,我一直收到重定向 uri 不匹配 - 我无法理解,因为从技术上讲,不需要重定向 uri我的流程案例...
详情如下:
在 Android 客户端:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
.requestServerAuthCode(serverClientId, false)
.build();
/**** bla.... ****/
GoogleSignInAccount acct = result.getSignInAccount();
String authCode = acct.getServerAuthCode();
/**** android app will send this authCode to my server ****/
/**** sample authCode: 4/Jny2Mxxx3x09sy4pqY3ZAwSTEz8rw2xxxxC-4VxxxxM
在我的后端服务器中:
try:
# i receive authCode correctly from android app.
# and use authCode to exchange to Access Token to google server as below:
credentials = client.credentials_from_clientsecrets_and_code(
app.config.get('GG_APP_SECRET'),
['https://www.googleapis.com/auth/plus.me', 'profile', 'email'],
authCode)
except Exception as e:
log.info('>>>>> I always receive: redirect uri missmatch here: %s <<<<<', e)
return generate_response(code=400, error=False, type='Fail', message=str(e))
这是来自我的后端服务器的 curl:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"authCode": "4/HP_cP_t70pgBrxxx7sjzCil7kaUHkxxxerdkMxxxrRg" \
}' 'http://localhost:5005/api/user/register/gg'
这是我的控制台设置:
问题:
android客户端中的serverClientId应该是上图的clientID吗?
我应该在上面的 google 控制台中输入的重定向 uri 是什么?
我应该 set/configure 我的重定向 uri 是什么?或者我需要做任何特定的设置吗?
好的,我去,
如果你看到 this
你会发现:
def credentials_from_clientsecrets_and_code(filename, scope, code,
message=None,
redirect_uri='postmessage',
http=None,
cache=None,
device_uri=None):
你意识到 redirect_uri = 'postmessage' 在我的情况下我没有 post 消息。
所以我要做的是将 redirect_uri
与我在 google 控制台
authorize redirect uri
相匹配
所以对于我上面问题中的情况,我将 python 代码更改为:
credentials = client.credentials_from_clientsecrets_and_code(
app.config.get('GG_APP_SECRET'),
['https://www.googleapis.com/auth/plus.me', 'profile', 'email'],
authCode, redirect_uri='https://developers.google.com/oauthplayground')