Skip to content

Commit

Permalink
Merge pull request #240 from holochain/app-ws-auth
Browse files Browse the repository at this point in the history
App ws auth
  • Loading branch information
ThetaSinner authored Apr 25, 2024
2 parents 3395427 + ccee833 commit 880c9a3
Show file tree
Hide file tree
Showing 20 changed files with 638 additions and 770 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
run: nix develop -c $SHELL -c "npm ci"

- name: Run tests
run: nix develop -c $SHELL -c "npm t"
run: nix develop --override-input versions/holochain "github:holochain/holochain/holochain-0.3.0-beta-dev.48" -c $SHELL -c "npm t"

- name: Setup tmate session if a previous step failed
if: ${{ failure() }}
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## \[Unreleased\]

### Added
- **BREAKING** Connecting an app websocket now requires an authentication token which can be obtained from the admin
websocket using `AdminWebsocket#issueAppAuthenticationToken`.

### Changed
- **BREAKING** Merged the app and app-agent websockets into a single `AppWebsocket` class. Following the addition of the
authentication token, the two types were well enough aligned that there was no longer a need to keep them separate.
- **BREAKING** App calls that previously required an `InstalledAppId` no longer require one because the websocket will
be authenticated with an app already, so the app interface no longer requires you to tell it which app you are calling.

### Fixed
### Removed

Expand Down
44 changes: 22 additions & 22 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
],
"scripts": {
"lint": "eslint --fix --ext .ts src test .eslintrc.cjs",
"test:app-agent": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/app-agent-websocket.ts",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"test:app-agent": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/app-websocket.ts",
"test:utils": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/utils.ts",
"test": "RUST_LOG=error RUST_BACKTRACE=1 tsx test/index.ts",
"build:lib": "rimraf ./lib && tsc -p tsconfig.build.json",
Expand Down
37 changes: 34 additions & 3 deletions src/api/admin/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action, DhtOp, Entry, ZomeCallCapGrant } from "../../hdk/index.js";
import { Action, DhtOp, Entry, ZomeCallCapGrant } from "../../hdk";
import {
ActionHash,
AgentPubKey,
Expand All @@ -17,7 +17,6 @@ import {
WasmHash,
} from "../../types.js";
import { Requester } from "../common.js";
import { DisableCloneCellRequest } from "../index.js";

/**
* @public
Expand Down Expand Up @@ -562,7 +561,16 @@ export type AddAgentInfoResponse = any;
/**
* @public
*/
export type DeleteCloneCellRequest = DisableCloneCellRequest;
export interface DeleteCloneCellRequest {
/**
* The app id that the clone cell belongs to
*/
app_id: InstalledAppId;
/**
* The clone id or cell id of the clone cell
*/
clone_cell_id: RoleName | CellId;
}

/**
* @public
Expand Down Expand Up @@ -813,6 +821,25 @@ export type StorageInfoRequest = void;
*/
export type StorageInfoResponse = StorageInfo;

/**
* @public
*/
export interface IssueAppAuthenticationTokenRequest {
installed_app_id: InstalledAppId;
expiry_seconds?: number;
single_use?: boolean;
}

export type AppAuthenticationToken = number[];

/**
* @public
*/
export interface IssueAppAuthenticationTokenResponse {
token: AppAuthenticationToken;
expires_at?: Timestamp;
}

/**
* @public
*/
Expand Down Expand Up @@ -861,6 +888,10 @@ export interface AdminApi {
GrantZomeCallCapabilityResponse
>;
storageInfo: Requester<StorageInfoRequest, StorageInfoResponse>;
issueAppAuthenticationToken: Requester<
IssueAppAuthenticationTokenRequest,
IssueAppAuthenticationTokenResponse
>;
dumpNetworkStats: Requester<
DumpNetworkStatsRequest,
DumpNetworkStatsResponse
Expand Down
7 changes: 7 additions & 0 deletions src/api/admin/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
GrantZomeCallCapabilityResponse,
InstallAppRequest,
InstallAppResponse,
IssueAppAuthenticationTokenRequest,
IssueAppAuthenticationTokenResponse,
ListAppInterfacesRequest,
ListAppInterfacesResponse,
ListAppsRequest,
Expand Down Expand Up @@ -272,6 +274,11 @@ export class AdminWebsocket implements AdminApi {
storageInfo: Requester<StorageInfoRequest, StorageInfoResponse> =
this._requester("storage_info");

issueAppAuthenticationToken: Requester<
IssueAppAuthenticationTokenRequest,
IssueAppAuthenticationTokenResponse
> = this._requester("issue_app_authentication_token");

dumpNetworkStats: Requester<
DumpNetworkStatsRequest,
DumpNetworkStatsResponse
Expand Down
2 changes: 0 additions & 2 deletions src/api/app-agent/index.ts

This file was deleted.

111 changes: 0 additions & 111 deletions src/api/app-agent/types.ts

This file was deleted.

Loading

0 comments on commit 880c9a3

Please sign in to comment.