Software /
code /
prosody-modules
File
mod_rest/example/prosody_oauth.py @ 5039:c0d243b27e64
mod_sasl2, mod_sasl_bind2, mod_sasl2_sm: Bump XEP-0388 namespace
This is the namespace for the proposed update to XEP-0388. I.e. not even
experimental yet... but this is all a work in progress anyway.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 13 Sep 2022 20:32:20 +0100 |
parent | 4952:ccce785f53e1 |
child | 5269:0e5a37f55440 |
line wrap: on
line source
from oauthlib.oauth2 import LegacyApplicationClient from requests_oauthlib import OAuth2Session class ProsodyRestClient(LegacyApplicationClient): pass class ProsodyRestSession(OAuth2Session): def __init__(self, base_url=None, token_url=None, rest_url=None, *args, **kwargs): if base_url and not token_url: token_url = base_url + "/oauth2/token" if base_url and not rest_url: rest_url = base_url + "/rest" self._prosody_rest_url = rest_url self._prosody_token_url = token_url super().__init__(client=ProsodyRestClient(*args, **kwargs)) def fetch_token(self, *args, **kwargs): return super().fetch_token(token_url=self._prosody_token_url, *args, **kwargs) def xmpp(self, json=None, *args, **kwargs): return self.post(self._prosody_rest_url, json=json, *args, **kwargs) if __name__ == "__main__": # Example usage # from prosody_oauth import ProsodyRestSession from getpass import getpass p = ProsodyRestSession(base_url=input("Base URL: "), client_id="app") p.fetch_token(username=input("XMPP Address: "), password=getpass("Password: ")) print(p.xmpp(json={"disco": True, "to": "jabber.org"}).json())