применение google-oauth2 в django - PullRequest
0 голосов
/ 05 мая 2020

Я пытаюсь использовать google auth2 и меня поражает тип запроса, который функция требует в django т.е.

try:
# Specify the CLIENT_ID of the app that accesses the backend:
idinfo = id_token.verify_oauth2_token(token, requests.Request(), CLIENT_ID)

# Or, if multiple clients access the backend server:
# idinfo = id_token.verify_oauth2_token(token, requests.Request())
# if idinfo['aud'] not in [CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]:
#     raise ValueError('Could not verify audience.')

if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
    raise ValueError('Wrong issuer.')

# If auth request is from a G Suite domain:
# if idinfo['hd'] != GSUITE_DOMAIN_NAME:
#     raise ValueError('Wrong hosted domain.')

# ID token is valid. Get the user's Google Account ID from the decoded token.
userid = idinfo['sub']

это из https://developers.google.com/identity/sign-in/web/backend-auth где запрос исходит от следующей функции

var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://yourbackend.example.com/tokensignin');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
  console.log('Signed in as: ' + xhr.responseText);
};
xhr.send('idtoken=' + id_token);

должен ли я передать его напрямую или просто значение токена

...