From 81ced64019c72335ee6c22d808cee91b4304ca8d Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Sat, 28 Sep 2024 17:04:22 -0700 Subject: [PATCH] Support current workspace in http proxy (#691) * support _token and remove prefix in login * allow pass workspace when login * Support current workspace for http endpoint * fix login optional * increase page size for list workspaces * Bump version for hypha-rpc 0.20.38 * Update change logs and login instructions --- CHANGELOG.md | 8 ++ docs/getting-started.md | 26 ++++++- docs/migration-guide.md | 10 +-- docs/service-type-annotation.md | 2 +- helm-charts/aks-hypha.md | 2 +- helm-charts/hypha-server/Chart.yaml | 2 +- helm-charts/hypha-server/values.yaml | 2 +- hypha/VERSION | 2 +- hypha/apps.py | 6 +- hypha/core/__init__.py | 2 + hypha/core/auth.py | 65 ++++++++++++---- hypha/core/store.py | 28 ++++--- hypha/core/workspace.py | 4 +- hypha/http.py | 16 ++-- hypha/templates/apps/login_template.html | 77 +++++++++++-------- .../hypha-core-app/hypha-app-webpython.js | 2 +- hypha/templates/ws/index.html | 2 +- hypha/websocket.py | 9 +++ requirements.txt | 2 +- setup.py | 2 +- 20 files changed, 183 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5fba2c7..ff7ed89e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Hypha Change Log +### 0.20.38 + - Allow passing workspace and expires_in to the `login` function to generate workspace specific token. + - When using http endpoint to access the service, you can now pass workspace specific token to the http header `Authorization` to access the service. (Previously, all the services are assumed to be accessed from the same service provider workspace) + +### 0.20.37 + - Add s3-proxy to allow accessing s3 presigned url in case the s3 server is not directly accessible. Use `--enable-s3-proxy` to enable the s3 proxy when starting Hypha. + - Add `artifact-manager` service to provide comprehensive artifact management, used for creating gallery-like service portal. The artifact manager service is backed by s3 storage and supports presigned url for direct access to the artifacts. This is a replacement of the previous `card` service. + ### 0.20.36 - Upgrade hypha-rpc to support updating reconnection token (otherwise it generate token expired error after some time) diff --git a/docs/getting-started.md b/docs/getting-started.md index 02a45dd7..96bba80e 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -220,7 +220,7 @@ svc = await get_remote_service("http://localhost:9527/ws-user-scintillating-lawy Include the following script in your HTML file to load the `hypha-rpc` client: ```html - + ``` Use the following code in JavaScript to connect to the server and access an existing service: @@ -250,7 +250,7 @@ By default all the clients connected to Hypha server communicate via the websock ### User Login and Token-Based Authentication -To access the full features of the Hypha server, users need to log in and obtain a token for authentication. The new `login()` function provides a convenient way to display a login URL, once the user click it and login, it can then return the token for connecting to the server. +To access the full features of the Hypha server, users need to log in and obtain a token for authentication. The `login()` function provides a convenient way to display a login URL, once the user click it and login, it can then return the token for connecting to the server. Here is an example of how the login process works using the `login()` function: @@ -294,7 +294,27 @@ The output will provide a URL for the user to open in their browser and perform the login process. Once the user clicks the link and successfully logs in, the `login()` function will return, providing the token. -The `login()` function also supports additional arguments: +#### Additional Arguments for Login + +You can specify the `workspace` and `expires_in` arguments in the `login()` function so that the token is generated for a specific workspace and expires after a certain period of time. + +```python +token = await login( + { + "server_url": SERVER_URL, + "workspace": "my-workspace", + "expires_in": 3600, + } +) +``` + +If a token is generated for a specific workspace, when calling `connect_to_server`, you need to specify the same workspace as well: + +```python +server = await connect_to_server({"server_url": "https://ai.imjoy.io", "token": token, "workspace": "my-workspace"}) +``` + +The `login()` function also supports other additional arguments: ```python token = await login( diff --git a/docs/migration-guide.md b/docs/migration-guide.md index f8dba6d3..979e3be7 100644 --- a/docs/migration-guide.md +++ b/docs/migration-guide.md @@ -15,7 +15,7 @@ To connect to the server, instead of installing the `imjoy-rpc` module, you will pip install -U hypha-rpc # new install ``` -We also changed our versioning strategy, we use the same version number for the server and client, so it's easier to match the client and server versions. For example, `hypha-rpc` version `0.20.37` is compatible with Hypha server version `0.20.37`. +We also changed our versioning strategy, we use the same version number for the server and client, so it's easier to match the client and server versions. For example, `hypha-rpc` version `0.20.38` is compatible with Hypha server version `0.20.38`. #### 2. Change the imports to use `hypha-rpc` @@ -128,10 +128,10 @@ loop.run_forever() To connect to the server, instead of using the `imjoy-rpc` module, you will need to use the `hypha-rpc` module. The `hypha-rpc` module is a standalone module that provides the RPC connection to the Hypha server. You can include it in your HTML using a script tag: ```html - + ``` -We also changed our versioning strategy, we use the same version number for the server and client, so it's easier to match the client and server versions. For example, `hypha-rpc` version `0.20.37` is compatible with Hypha server version `0.20.37`. +We also changed our versioning strategy, we use the same version number for the server and client, so it's easier to match the client and server versions. For example, `hypha-rpc` version `0.20.38` is compatible with Hypha server version `0.20.38`. #### 2. Change the connection method and use camelCase for service function names @@ -149,7 +149,7 @@ Here is a suggested list of search and replace operations to update your code: Here is an example of how the updated code might look: ```html - + + +