def _set_oauth_user_vars(token_info, audiences, allowed_client_ids, scopes,
                         local_dev):
  """Validate the oauth token and set endpoints auth user variables.

  If the oauth token is valid, this sets either the ENDPOINTS_AUTH_EMAIL and
  ENDPOINTS_AUTH_DOMAIN environment variables (in local development) or
  the ENDPOINTS_USE_OAUTH_SCOPE one.  These provide enough information
  that our endpoints.get_current_user() function can get the user.

  Args:
    token_info: Info returned about the oauth token from the tokeninfo endpoint.
    audiences: List of audiences that are acceptable, or None for first-party.
    allowed_client_ids: List of client IDs that are acceptable.
    scopes: List of acceptable scopes.
    local_dev: True if we're running a local dev server, false if we're in prod.
  """
  if 'email' not in token_info:
    logging.warning('Oauth token doesn\'t include an email address.')
    return
  if not token_info.get('verified_email'):
    logging.warning('Oauth token email isn\'t verified.')
    return




  if audiences or allowed_client_ids:
    if 'audience' not in token_info:
      logging.warning('Audience is required and isn\'t specified in token.')
      return




    if token_info['audience'] in audiences:
      pass
    elif (token_info['audience'] == token_info.get('issued_to') and
          allowed_client_ids is not None and
          token_info['audience'] in allowed_client_ids):
      pass
    else:
      logging.warning('Oauth token audience isn\'t permitted.')
      return


  token_scopes = token_info.get('scope', '').split(' ')
  if not any(scope in scopes for scope in token_scopes):
    logging.warning('Oauth token scopes don\'t match any acceptable scopes.')
    return

  if local_dev:





    os.environ[_ENV_AUTH_EMAIL] = token_info['email']
    os.environ[_ENV_AUTH_DOMAIN] = ''
    return



  for scope in scopes:
    try:
      oauth_user = oauth.get_current_user(scope)
      oauth_scope = scope
      break
    except oauth.Error:

      pass
  else:
    logging.warning('Oauth framework couldn\'t find a user.')
    return None
  if oauth_user.email() == token_info['email']:
    os.environ[_ENV_USE_OAUTH_SCOPE] = oauth_scope
    return

  logging.warning('Oauth framework user didn\'t match oauth token user.')
  return None
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/ext/endpoints/users_id_token.py/_set_oauth_user_vars/original