Fix login on main bitwarden instance
This commit is contained in:
parent
31cf9746d5
commit
ca320de77c
|
@ -3,6 +3,7 @@ package bitwarden
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -71,13 +72,13 @@ func connectToWebsocket(ctx context.Context, vault *vault.Vault, cfg *config.Con
|
|||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
|
||||
url, err := url.Parse(cfg.ConfigFile.ApiUrl)
|
||||
url, err := url.Parse(cfg.ConfigFile.NotificationsUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
token, err := cfg.GetToken()
|
||||
var websocketURL = "wss://" + url.Host + "/notifications/hub?access_token=" + token.AccessToken
|
||||
var websocketURL = "wss://" + url.Host + url.Path + "/hub?access_token=" + token.AccessToken
|
||||
c, _, err := websocket.DefaultDialer.Dial(websocketURL, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -87,11 +88,14 @@ func connectToWebsocket(ctx context.Context, vault *vault.Vault, cfg *config.Con
|
|||
websocketLog.Info("Connected to websocket server...")
|
||||
|
||||
done := make(chan struct{})
|
||||
//handshake required for official bitwarden implementation
|
||||
c.WriteMessage(1, []byte(`{"protocol":"messagepack","version":1}`))
|
||||
|
||||
go func() {
|
||||
defer close(done)
|
||||
for {
|
||||
_, message, err := c.ReadMessage()
|
||||
mt, message, err := c.ReadMessage()
|
||||
fmt.Println(mt)
|
||||
if err != nil {
|
||||
websocketLog.Error("Error reading websocket message %s", err)
|
||||
return
|
||||
|
|
|
@ -37,6 +37,7 @@ type RuntimeConfig struct {
|
|||
WebsocketDisabled bool
|
||||
ApiURI string
|
||||
IdentityURI string
|
||||
NotificationsURI string
|
||||
SingleProcess bool
|
||||
DeviceUUID string
|
||||
User string
|
||||
|
@ -47,6 +48,7 @@ type RuntimeConfig struct {
|
|||
type ConfigFile struct {
|
||||
IdentityUrl string
|
||||
ApiUrl string
|
||||
NotificationsUrl string
|
||||
DeviceUUID string
|
||||
ConfigKeyHash string
|
||||
EncryptedToken string
|
||||
|
@ -75,8 +77,9 @@ func DefaultConfig() Config {
|
|||
return Config{
|
||||
memguard.NewBuffer(32),
|
||||
ConfigFile{
|
||||
IdentityUrl: "https://identity.bitwarden.com/",
|
||||
ApiUrl: "https://identity.bitwarden.com/",
|
||||
IdentityUrl: "https://vault.bitwarden.com/identity",
|
||||
ApiUrl: "https://vault.bitwarden.com/api",
|
||||
NotificationsUrl: "https://notifications.bitwarden.com",
|
||||
DeviceUUID: deviceUUID.String(),
|
||||
ConfigKeyHash: "",
|
||||
EncryptedToken: "",
|
||||
|
|
|
@ -106,7 +106,8 @@ func StartUnixAgent(path string, runtimeConfig config.RuntimeConfig) error {
|
|||
var vault = vault.NewVault(&keyring)
|
||||
cfg, err := config.ReadConfig(runtimeConfig)
|
||||
if err != nil {
|
||||
var cfg = config.DefaultConfig()
|
||||
cfg = config.DefaultConfig()
|
||||
cfg.ConfigFile.RuntimeConfig = runtimeConfig
|
||||
cfg.WriteConfig()
|
||||
}
|
||||
cfg.ConfigFile.RuntimeConfig = runtimeConfig
|
||||
|
@ -116,6 +117,9 @@ func StartUnixAgent(path string, runtimeConfig config.RuntimeConfig) error {
|
|||
if cfg.ConfigFile.RuntimeConfig.IdentityURI != "" {
|
||||
cfg.ConfigFile.IdentityUrl = cfg.ConfigFile.RuntimeConfig.IdentityURI
|
||||
}
|
||||
if cfg.ConfigFile.RuntimeConfig.NotificationsURI != "" {
|
||||
cfg.ConfigFile.NotificationsUrl = cfg.ConfigFile.RuntimeConfig.NotificationsURI
|
||||
}
|
||||
if cfg.ConfigFile.RuntimeConfig.DeviceUUID != "" {
|
||||
cfg.ConfigFile.DeviceUUID = cfg.ConfigFile.RuntimeConfig.DeviceUUID
|
||||
}
|
||||
|
|
|
@ -89,6 +89,9 @@ func StartVirtualAgent(runtimeConfig config.RuntimeConfig) (chan []byte, chan []
|
|||
if cfg.ConfigFile.RuntimeConfig.IdentityURI != "" {
|
||||
cfg.ConfigFile.IdentityUrl = cfg.ConfigFile.RuntimeConfig.IdentityURI
|
||||
}
|
||||
if cfg.ConfigFile.RuntimeConfig.NotificationsURI != "" {
|
||||
cfg.ConfigFile.NotificationsUrl = cfg.ConfigFile.RuntimeConfig.NotificationsURI
|
||||
}
|
||||
if cfg.ConfigFile.RuntimeConfig.DeviceUUID != "" {
|
||||
cfg.ConfigFile.DeviceUUID = cfg.ConfigFile.RuntimeConfig.DeviceUUID
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue