diff --git a/Makefile b/Makefile index a6874ce..3f9d161 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ test-e2e-quick: .PHONY: build clean test deps tidy fmt vet lint install-hooks redeploy-devnet redeploy-testnet release health -VERSION := 0.104.0 +VERSION := 0.105.0 COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)' diff --git a/pkg/auth/phantom.go b/pkg/auth/phantom.go index 6e6a1e3..856245d 100644 --- a/pkg/auth/phantom.go +++ b/pkg/auth/phantom.go @@ -16,8 +16,17 @@ import ( qrterminal "github.com/mdp/qrterminal/v3" ) -// Hardcoded Phantom auth React app URL (deployed on Orama devnet) -const phantomAuthURL = "https://phantom-auth-y0w9aa.orama-devnet.network" +// defaultPhantomAuthURL is the default Phantom auth React app URL (deployed on Orama devnet). +// Override with ORAMA_PHANTOM_AUTH_URL environment variable. +const defaultPhantomAuthURL = "https://phantom-auth-y0w9aa.orama-devnet.network" + +// phantomAuthURL returns the Phantom auth URL, preferring the environment variable. +func phantomAuthURL() string { + if u := os.Getenv("ORAMA_PHANTOM_AUTH_URL"); u != "" { + return strings.TrimRight(u, "/") + } + return defaultPhantomAuthURL +} // PhantomSession represents a phantom auth session from the gateway. type PhantomSession struct { @@ -76,7 +85,7 @@ func PerformPhantomAuthentication(gatewayURL, namespace string) (*Credentials, e // 2. Build auth URL and display QR code authURL := fmt.Sprintf("%s/?session=%s&gateway=%s&namespace=%s", - phantomAuthURL, session.SessionID, url.QueryEscape(gatewayURL), url.QueryEscape(namespace)) + phantomAuthURL(), session.SessionID, url.QueryEscape(gatewayURL), url.QueryEscape(namespace)) fmt.Println("\nScan this QR code with your phone to authenticate:") fmt.Println() diff --git a/pkg/auth/simple_auth.go b/pkg/auth/simple_auth.go index 3b5f7b5..5e54fb3 100644 --- a/pkg/auth/simple_auth.go +++ b/pkg/auth/simple_auth.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "net/url" "os" "strings" "time" @@ -336,22 +337,15 @@ func retryAPIKeyRequest(gatewayURL string, client *http.Client, wallet, namespac return apiKey, nil } -// extractDomainFromURL extracts the domain from a URL -// Removes protocol (https://, http://), path, and port components -func extractDomainFromURL(url string) string { - // Remove protocol prefixes - url = strings.TrimPrefix(url, "https://") - url = strings.TrimPrefix(url, "http://") - - // Remove path component - if idx := strings.Index(url, "/"); idx != -1 { - url = url[:idx] +// extractDomainFromURL extracts the hostname from a URL, stripping scheme, port, and path. +func extractDomainFromURL(rawURL string) string { + // Ensure the URL has a scheme so net/url.Parse works correctly + if !strings.Contains(rawURL, "://") { + rawURL = "https://" + rawURL } - - // Remove port component - if idx := strings.Index(url, ":"); idx != -1 { - url = url[:idx] + u, err := url.Parse(rawURL) + if err != nil { + return "" } - - return url + return u.Hostname() } diff --git a/pkg/auth/wallet.go b/pkg/auth/wallet.go index 0a9344d..5be457c 100644 --- a/pkg/auth/wallet.go +++ b/pkg/auth/wallet.go @@ -168,7 +168,7 @@ func (as *AuthServer) handleCallback(w http.ResponseWriter, r *http.Request) { return } - // Send success response to browser + // Send success response to browser (API key is never exposed in HTML) w.Header().Set("Content-Type", "text/html") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` @@ -181,30 +181,25 @@ func (as *AuthServer) handleCallback(w http.ResponseWriter, r *http.Request) { .container { background: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); max-width: 500px; margin: 0 auto; } .success { color: #4CAF50; font-size: 48px; margin-bottom: 20px; } .details { background: #f8f9fa; padding: 20px; border-radius: 5px; margin: 20px 0; text-align: left; } - .key { font-family: monospace; background: #e9ecef; padding: 10px; border-radius: 3px; word-break: break-all; }
You have successfully authenticated with your wallet.
API Key:
-Namespace: %s
Wallet: %s
%sYour credentials have been saved securely to ~/.orama/credentials.json
You can now close this browser window and return to your terminal.
+Your credentials have been saved securely. Return to your terminal to continue.
+You can now close this browser window.