ovos-PHAL-plugin-oauth


Nameovos-PHAL-plugin-oauth JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/OpenVoiceOS/ovos-PHAL-plugin-oauth
SummaryA plugin for OpenVoiceOS hardware abstraction layer
upload_time2024-11-20 11:58:57
maintainerNone
docs_urlNone
authorJarbasAi
requires_pythonNone
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements ovos-utils ovos-bus-client Flask oauthlib qrcode
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PHAL OAuth Plugin

WIP

## Bus API

Listens for
```python
# skills register app on load or on oauth.ping
self.bus.on("oauth.register", self.handle_oauth_register)

# this triggers the ovos shell oauth flow
self.bus.on("oauth.start", self.handle_start_oauth)

# when ovos shell sends client_id/secret add it to db and continue oauth flow
self.bus.on("ovos.shell.oauth.register.credentials", self.handle_client_secret)

# this returns the oauth url for any external UI that wants to use it
self.bus.on("oauth.get", self.handle_get_auth_url)
```

Emits
```python
# on plugin load trigger register events from oauth skills that were loaded already
self.bus.emit(Message("oauth.ping"))

# on oauth.get send oauth.url
self.bus.emit(message.reply("oauth.url", {"url": url}))

# on oauth.start flow trigger ovos shell UI
self.bus.emit(message.forward(
        "ovos.shell.oauth.start.authentication",
        {"url": url, "needs_credentials": self.oauth_skills[skill_id]["needs_creds"]})
    )
```

## Registering OAuth app with the plugin

send OAuth info in `oauth.register`

```python
skill_id = message.data.get("skill_id")
app_id = message.data.get("app_id")
munged_id = f"{skill_id}_{app_id}"  # key for oauth db

# these fields are app specific and provided by skills
auth_endpoint = message.data.get("auth_endpoint")
token_endpoint = message.data.get("token_endpoint")
refresh_endpoint = message.data.get("refresh_endpoint")
cb_endpoint = f"http://0.0.0.0:{self.port}/auth/callback/{munged_id}"
scope = message.data.get("scope")

# some skills may require users to input these, other may provide it
# this will depend on the app TOS
client_id = message.data.get("client_id")
client_secret = message.data.get("client_secret")
```

---------------------------------------
## QR Code - Remote OAuth Integration Flow

* Note: This flow requires the a GUI to display the QR Code that can be scanned by the user using any external device. This also requires the port for the oauth app to be unblocked on the ufw.

### **Example Usage From A Skill / Plugin**

``` python
self.skill_id = "my_skill_id"
self.app_id = "my_app_id"
self.client_id = None
self.munged_id = f"{self.skill_id}_{self.app_id}"
self.bus.on("oauth.app.host.info.response", self.handle_host_response)
self.bus.on("oauth.generate.qr.response", self.handle_qr_generated)
self.bus.on("oauth.token.response.{self.munged_id}", self.handle_token_response)

def handle_host_response(self, message):
    # Some apps with OAuth Spec 2.0 require client_id to match the redirect_uri address and port, set the client id before registering the skill, send a request to "oauth.get.app.host.info" to get the host and port
    host = message.data.get("host", None)
    port = message.data.get("port", None)
    self.client_id = f"http://{host}:{port}"

def register_skill(self):
    client_secret = "my_client_secret"
    auth_endpoint = "https://example.com/auth"
    token_endpoint = "https://example.com/auth/token"
    self.bus.emit(Message("oauth.register", {
        "skill_id": self.skill_id, #Required
        "app_id": self.app_id, #Required
        "client_id": self.client_id, #Optional - Some apps may require this
        "client_secret": client_secret, #Optional - Some apps may require this
        "auth_endpoint": auth_endpoint, #Required
        "token_endpoint": token_endpoint, #Required
        "refresh_endpoint": "", #Optional - Some apps may require this
        "scope": "", #Optional - Some apps may require this
        "shell_integration": True #Optional - mark as false if app/skill handles displaying generated QR code. mark as true if shell should handle it.
    }))

def start_qr_generation(self):
    self.bus.emit(Message("oauth.generate.qr.request", {
        "app_id": self.app_id, # Required
        "skill_id": self.skill_id # Required
    }))

def handle_qr_generated(self, message):
    qr = message.data.get("qr", None)
    # Use GUI to display the generated QR Code
    # somewhere in your QML UI
    self.gui["qr_image_path"] = qr

def handle_token_response(self, message):
    response = message.data
    access_token = response.get("access_token", None)
    # Do something with access_token once oauth flow is complete

# Always register the skill first before requesting the QR Code to be generated
self.register_skill()
self.start_qr_flow()
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/OpenVoiceOS/ovos-PHAL-plugin-oauth",
    "name": "ovos-PHAL-plugin-oauth",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "JarbasAi",
    "author_email": "jarbasai@mailfence.com",
    "download_url": "https://files.pythonhosted.org/packages/92/2f/60ba1364cc89e24d81192fad6d5e9b8469461a97f1c5a4a0fa06d19346d5/ovos-PHAL-plugin-oauth-0.1.3.tar.gz",
    "platform": null,
    "description": "# PHAL OAuth Plugin\n\nWIP\n\n## Bus API\n\nListens for\n```python\n# skills register app on load or on oauth.ping\nself.bus.on(\"oauth.register\", self.handle_oauth_register)\n\n# this triggers the ovos shell oauth flow\nself.bus.on(\"oauth.start\", self.handle_start_oauth)\n\n# when ovos shell sends client_id/secret add it to db and continue oauth flow\nself.bus.on(\"ovos.shell.oauth.register.credentials\", self.handle_client_secret)\n\n# this returns the oauth url for any external UI that wants to use it\nself.bus.on(\"oauth.get\", self.handle_get_auth_url)\n```\n\nEmits\n```python\n# on plugin load trigger register events from oauth skills that were loaded already\nself.bus.emit(Message(\"oauth.ping\"))\n\n# on oauth.get send oauth.url\nself.bus.emit(message.reply(\"oauth.url\", {\"url\": url}))\n\n# on oauth.start flow trigger ovos shell UI\nself.bus.emit(message.forward(\n        \"ovos.shell.oauth.start.authentication\",\n        {\"url\": url, \"needs_credentials\": self.oauth_skills[skill_id][\"needs_creds\"]})\n    )\n```\n\n## Registering OAuth app with the plugin\n\nsend OAuth info in `oauth.register`\n\n```python\nskill_id = message.data.get(\"skill_id\")\napp_id = message.data.get(\"app_id\")\nmunged_id = f\"{skill_id}_{app_id}\"  # key for oauth db\n\n# these fields are app specific and provided by skills\nauth_endpoint = message.data.get(\"auth_endpoint\")\ntoken_endpoint = message.data.get(\"token_endpoint\")\nrefresh_endpoint = message.data.get(\"refresh_endpoint\")\ncb_endpoint = f\"http://0.0.0.0:{self.port}/auth/callback/{munged_id}\"\nscope = message.data.get(\"scope\")\n\n# some skills may require users to input these, other may provide it\n# this will depend on the app TOS\nclient_id = message.data.get(\"client_id\")\nclient_secret = message.data.get(\"client_secret\")\n```\n\n---------------------------------------\n## QR Code - Remote OAuth Integration Flow\n\n* Note: This flow requires the a GUI to display the QR Code that can be scanned by the user using any external device. This also requires the port for the oauth app to be unblocked on the ufw.\n\n### **Example Usage From A Skill / Plugin**\n\n``` python\nself.skill_id = \"my_skill_id\"\nself.app_id = \"my_app_id\"\nself.client_id = None\nself.munged_id = f\"{self.skill_id}_{self.app_id}\"\nself.bus.on(\"oauth.app.host.info.response\", self.handle_host_response)\nself.bus.on(\"oauth.generate.qr.response\", self.handle_qr_generated)\nself.bus.on(\"oauth.token.response.{self.munged_id}\", self.handle_token_response)\n\ndef handle_host_response(self, message):\n    # Some apps with OAuth Spec 2.0 require client_id to match the redirect_uri address and port, set the client id before registering the skill, send a request to \"oauth.get.app.host.info\" to get the host and port\n    host = message.data.get(\"host\", None)\n    port = message.data.get(\"port\", None)\n    self.client_id = f\"http://{host}:{port}\"\n\ndef register_skill(self):\n    client_secret = \"my_client_secret\"\n    auth_endpoint = \"https://example.com/auth\"\n    token_endpoint = \"https://example.com/auth/token\"\n    self.bus.emit(Message(\"oauth.register\", {\n        \"skill_id\": self.skill_id, #Required\n        \"app_id\": self.app_id, #Required\n        \"client_id\": self.client_id, #Optional - Some apps may require this\n        \"client_secret\": client_secret, #Optional - Some apps may require this\n        \"auth_endpoint\": auth_endpoint, #Required\n        \"token_endpoint\": token_endpoint, #Required\n        \"refresh_endpoint\": \"\", #Optional - Some apps may require this\n        \"scope\": \"\", #Optional - Some apps may require this\n        \"shell_integration\": True #Optional - mark as false if app/skill handles displaying generated QR code. mark as true if shell should handle it.\n    }))\n\ndef start_qr_generation(self):\n    self.bus.emit(Message(\"oauth.generate.qr.request\", {\n        \"app_id\": self.app_id, # Required\n        \"skill_id\": self.skill_id # Required\n    }))\n\ndef handle_qr_generated(self, message):\n    qr = message.data.get(\"qr\", None)\n    # Use GUI to display the generated QR Code\n    # somewhere in your QML UI\n    self.gui[\"qr_image_path\"] = qr\n\ndef handle_token_response(self, message):\n    response = message.data\n    access_token = response.get(\"access_token\", None)\n    # Do something with access_token once oauth flow is complete\n\n# Always register the skill first before requesting the QR Code to be generated\nself.register_skill()\nself.start_qr_flow()\n```\n\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A plugin for OpenVoiceOS hardware abstraction layer",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/OpenVoiceOS/ovos-PHAL-plugin-oauth"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5c7d0efb242c9cd5fb27660bc537d17142cb5744690aff59fa96060ca1d56143",
                "md5": "d607b14f298f79932c6adb4ddab8ecd5",
                "sha256": "60bd19944cf09945d018133d7d57cd91a1df906af9f24b82e0e5de699eef0130"
            },
            "downloads": -1,
            "filename": "ovos_PHAL_plugin_oauth-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d607b14f298f79932c6adb4ddab8ecd5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11920,
            "upload_time": "2024-11-20T11:58:55",
            "upload_time_iso_8601": "2024-11-20T11:58:55.695249Z",
            "url": "https://files.pythonhosted.org/packages/5c/7d/0efb242c9cd5fb27660bc537d17142cb5744690aff59fa96060ca1d56143/ovos_PHAL_plugin_oauth-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "922f60ba1364cc89e24d81192fad6d5e9b8469461a97f1c5a4a0fa06d19346d5",
                "md5": "22b1a84361492ac397d7373a970b7c86",
                "sha256": "99901cc4919b27523faaf87fe78c3c049875a854798028a818908a70e8232dd1"
            },
            "downloads": -1,
            "filename": "ovos-PHAL-plugin-oauth-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "22b1a84361492ac397d7373a970b7c86",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12112,
            "upload_time": "2024-11-20T11:58:57",
            "upload_time_iso_8601": "2024-11-20T11:58:57.203438Z",
            "url": "https://files.pythonhosted.org/packages/92/2f/60ba1364cc89e24d81192fad6d5e9b8469461a97f1c5a4a0fa06d19346d5/ovos-PHAL-plugin-oauth-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 11:58:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "OpenVoiceOS",
    "github_project": "ovos-PHAL-plugin-oauth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "ovos-utils",
            "specs": [
                [
                    "<",
                    "1.0.0"
                ],
                [
                    ">=",
                    "0.4.1"
                ]
            ]
        },
        {
            "name": "ovos-bus-client",
            "specs": [
                [
                    "<",
                    "2.0.0"
                ],
                [
                    ">=",
                    "0.0.3"
                ]
            ]
        },
        {
            "name": "Flask",
            "specs": [
                [
                    ">=",
                    "0.12"
                ]
            ]
        },
        {
            "name": "oauthlib",
            "specs": [
                [
                    "~=",
                    "3.0"
                ]
            ]
        },
        {
            "name": "qrcode",
            "specs": [
                [
                    "~=",
                    "7.3.1"
                ]
            ]
        }
    ],
    "lcname": "ovos-phal-plugin-oauth"
}
        
Elapsed time: 0.68521s