0

我尝试下面建立然而this步骤无法交换访问令牌身份验证令牌重定向URI missmatch

,我不断收到重定向URI missmatch当我试图交换授权码(由我的手机应用程序给出)到谷歌服务器 - 我无法理解,因为技术上没有重定向uri需要我的流量情况...

这里是细节S:

在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 -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ 
    "authCode": "4/HP_cP_t70pgBrxxx7sjzCil7kaUHkxxxerdkMxxxrRg" \ 
}' 'http://localhost:5005/api/user/register/gg' 

这是我的控制台设置:

enter image description here

问题:

是假设是上图中的clientID的在Android客户端的serverClientId?

什么是我应该放在谷歌控制台上面的重定向uri?

我应该为我的redirect uri设置/配置什么?或者是否有我需要做的特定设置?

+0

考虑调用http端点,而不是试图弄清楚这个库在做什么。它只是两个简单的http POSTS,你可以在oauthplayground中看到。 – pinoyyid

+0

谢谢,但这里的主要问题是为什么谷歌告诉我,uri mismatch?我不知道什么是重定向uri,因为我的情况混合流,因此没有重定向uri。 – AnD

+0

如何粘贴你的代码,以便我们可以看到你正在尝试做什么 – pinoyyid

回答

0

好,我走了,

如果你看到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的',这在我的情况我没有交信息。

所以我要做的就是以匹配redirect_uriauthorize 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')