0
我試圖通過Google雲端點從Android應用程序進行認證請求時,在我的Google開發者控制檯日誌中收到「觀衆不允許」警告。由於雲端點中的「觀衆不允許」警告導致get_current_user()返回無
通過端點源代碼來看,對應於:
aud = parsed_token.get('aud')
cid = parsed_token.get('azp')
if aud != cid and aud not in audiences:
logging.warning('Audience not allowed: %s', aud)
在Android應用我的調用代碼:
public static final String WEB_CLIENT_ID = "web-client-id.apps.googleusercontent.com";
public static final String AUDIENCE = "server:client_id:" + WEB_CLIENT_ID;
GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(
mContext,
AUDIENCE
);
Grapi.Builder builder = new Grapi.Builder(HTTP_TRANSPORT,
JSON_FACTORY, credential);
Grapi service = builder.build()
其中「網絡客戶端ID」是字母數字客戶端ID在谷歌開發者控制檯中生成。該服務用於進行經認證的呼叫。
這也是被傳遞給API裝飾在我的後端Python代碼相同WEB_CLIENT_ID:
WEB_CLIENT_ID = 'web-client-id.apps.googleusercontent.com'
ANDROID_CLIENT_ID = 'android-client-id.apps.googleusercontent.com'
ANDROID_AUDIENCE = WEB_CLIENT_ID
grapi_client_ids = [ANDROID_CLIENT_ID,
WEB_CLIENT_ID,
endpoints.API_EXPLORER_CLIENT_ID]
grapi_audiences = [ANDROID_AUDIENCE]
@endpoints.api(name='grapi', version='v1',
allowed_client_ids=grapi_client_ids, audiences=grapi_audiences,
scopes=[endpoints.EMAIL_SCOPE])
它看起來像所有這一切都是造成endpoints.get_current_user()返回無,我的身份驗證呼叫失敗。