Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(websocket): add process to authenticate websocket connections #1921

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/qri-io/qri/auth/token"
"github.com/qri-io/qri/lib"
qhttp "github.com/qri-io/qri/lib/http"
"github.com/qri-io/qri/lib/websocket"
"github.com/qri-io/qri/version"
)

Expand All @@ -39,7 +40,7 @@ func init() {
type Server struct {
*lib.Instance
Mux *mux.Router
websocket lib.WebsocketHandler
websocket websocket.Handler
}

// New creates a new qri server from a p2p node & configuration
Expand All @@ -56,7 +57,7 @@ func (s Server) Serve(ctx context.Context) (err error) {

node.LocalStreams.Print(fmt.Sprintf("qri version v%s\nconnecting...\n", APIVersion))

ws, err := lib.NewWebsocketHandler(ctx, s.Instance)
ws, err := websocket.NewHandler(ctx, s.Instance.Bus(), s.Instance.KeyStore())
if err != nil {
return err
}
Expand Down Expand Up @@ -133,7 +134,7 @@ func readOnlyResponse(w http.ResponseWriter, endpoint string) {
func (s *Server) HomeHandler(w http.ResponseWriter, r *http.Request) {
upgrade := r.Header.Get("Upgrade")
if upgrade == "websocket" {
s.websocket.WSConnectionHandler(w, r)
s.websocket.ConnectionHandler(w, r)
} else {
if r.URL.Path == "" || r.URL.Path == "/" {
HealthCheckHandler(w, r)
Expand Down
8 changes: 8 additions & 0 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,14 @@ func (inst *Instance) TokenProvider() token.Provider {
return inst.tokenProvider
}

// KeyStore exposes the instance key.Store
func (inst *Instance) KeyStore() key.Store {
if inst == nil {
return nil
}
return inst.keystore
}

// activeProfile tries to extract the current user from values embedded in the
// passed-in context, falling back to the repo owner as a default active profile
func (inst *Instance) activeProfile(ctx context.Context) (pro *profile.Profile, err error) {
Expand Down
71 changes: 0 additions & 71 deletions lib/websocket.go

This file was deleted.

Loading