wsauth

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 2 Imported by: 0

README

workflow-plugin-ws-auth

WebSocket HMAC authentication plugin for the workflow framework.

go get github.com/GoCodeAlone/workflow-plugin-ws-auth

Features

  • HMAC-SHA256 challenge-response handshake
  • Per-connection key derivation via HKDF-SHA256
  • Sequence-based replay protection
  • JWT claim extraction (player_type, sub)
  • Bidirectional connection <-> player mapping
  • Constant-time signature comparison

Auth Flow

sequenceDiagram
    participant C as Client
    participant S as Server

    C->>S: WebSocket connect
    S->>C: challenge {nonce, timestamp, server_id}
    C->>S: handshake {signature, player_type, session_id, auth_token}
    Note over S: Verify HMAC-SHA256 signature<br/>Extract JWT claims<br/>Derive per-connection key (HKDF)
    S->>C: handshake_ok {hmac_key}
    C->>S: signed message {seq, payload, signature}
    Note over S: Verify HMAC + sequence
    S->>C: response

Configuration

Module type: ws_auth.hmac

modules:
  my_auth:
    type: ws_auth.hmac
    config:
      shared_secret: "your-secret-key"
      server_id: "my-server"

The shared secret can also be set via the SDK_SECRET environment variable (takes precedence over config).

Pipeline Step

Step type: step.ws_auth_identity

Extracts the player ID from an authenticated WebSocket connection.

steps:
  - name: identify
    type: step.ws_auth_identity
    config:
      connection_id: "{{.connectionId}}"

Output:

  • player_id -- the authenticated player's ID
  • authenticated -- boolean indicating whether the connection is authenticated

Build & Test

go build ./...
go test ./...

Requires Go 1.26+ and depends on:

  • github.com/GoCodeAlone/workflow v0.19.0
  • golang.org/x/crypto (HKDF)

License

MIT

Documentation

Overview

Package wsauth provides the workflow-plugin-ws-auth SDK plugin. It implements HMAC-SHA256 challenge-response authentication for WebSocket connections with per-connection key derivation and sequence-based replay protection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWSAuthPlugin

func NewWSAuthPlugin() sdk.PluginProvider

NewWSAuthPlugin returns the ws-auth SDK plugin provider.

Types

type ProtocolEnforcer

type ProtocolEnforcer = internal.ProtocolEnforcer

ProtocolEnforcer manages HMAC handshakes and validates signed messages.

func GetEnforcer

func GetEnforcer() *ProtocolEnforcer

GetEnforcer returns the global protocol enforcer once the ws_auth.hmac module has initialized. Returns nil if the module has not started yet.

func NewProtocolEnforcer

func NewProtocolEnforcer(sdkSecret []byte, serverID string) *ProtocolEnforcer

NewProtocolEnforcer creates a standalone protocol enforcer (useful for testing).

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL