code: def _generateForOAuthSecurity(self, client_id,
                                    secret_id, token_url=None):
          
          grant_type="client_credentials"
          if token_url is None:
              token_url = "https://www.arcgis.com/sharing/rest/oauth2/token"
          params = {
              "client_id" : client_id,
              "client_secret" : secret_id,
              "grant_type":grant_type,
              "f" : "json"
          }
          token = self._post(url=token_url,
                                param_dict=params,
                                securityHandler=None,
                                proxy_port=self._proxy_port,
                                proxy_url=self._proxy_url)
          if 'access_token' in token:
              self._token = token['access_token']
              self._expires_in = token['expires_in']
              self._token_created_on = datetime.datetime.now()
              self._token_expires_on = self._token_created_on + datetime.timedelta(seconds=int(token['expires_in']))
              self._valid = True
              self._message = "Token Generated"
          else:
              self._token = None
              self._expires_in = None
              self._token_created_on = None
              self._token_expires_on = None
              self._valid = False
              self._message = token
docs: generates a token based on the OAuth security model