AppIdentityError:验证Bearer令牌时收件人错误

时间:2015-08-28 12:22:33

标签: python google-app-engine oauth-2.0 google-schemas

我们在应用程序中使用单击操作电子邮件标记。我们的电子邮件已在白名单中列出了我们发送电子邮件的电子邮件ID(XXX@YYY.com)。

当我们尝试验证承载令牌时,我们收到 AppIdentityError:错误的收件人。完成堆栈跟踪:

  

文件" ./ app / components / happier_pages / py / lib / oauth2client / util.py",   第141行,位于position_wrapper中       return wrapped(* args,** kwargs)File" ./ app / components / happier_pages / py / lib / oauth2client / client.py",line   1706,在verify_id_token中       return crypt.verify_signed_jwt_with_certs(id_token,certs,audience)文件   " ./ app / components / happier_pages / py / lib / oauth2client / crypt.py",line   170,在verify_signed_jwt_with_certs中(aud,audience,json_body))   AppIdentityError:错误的收件人," domain.com" !=   "服务账户-ID"   {" ISS":" accounts.google.com"" AUD":" mydomain.com""子&#34 ;:" 1234556789"" email_verified":真," AZP":" gmail@system.gserviceaccount.com"," ID":" 123456789"" verified_email":真,"电子邮件":" gmail@system.gserviceaccount.com",& #34; CID":" gmail@system.gserviceaccount.com"," IAT" 123"&EXP#34; 123}

以下是验证持有人令牌的代码段:

GMAIL_ISSUEE = 'gmail@system.gserviceaccount.com'
GOOGLE_API_CLIENT_SERVICE_ID = 'xxxxx@developer.gserviceaccount.com'
BEARER_TOKEN=self.request.headers["Authorization"].split('Bearer ')[1]
token = client.verify_id_token(BEARER_TOKEN.strip(), GOOGLE_API_CLIENT_SERVICE_ID)

以上代码摘自https://developers.google.com/gmail/markup/actions/verifying-bearer-tokens

1 个答案:

答案 0 :(得分:2)

@Sagar已经证实这有效。

而不是:

client.verify_id_token(BEARER_TOKEN, GOOGLE_API_CLIENT_SERVICE_ID) 

将发件人域名用作目标受众:

client.verify_id_token(BEARER_TOKEN, "yourdomain.com")