forked from mirror/mautrix-discord
Update to remote auth v2
This commit is contained in:
parent
0e12bd58d6
commit
704bdaefd7
4 changed files with 31 additions and 15 deletions
4
go.mod
4
go.mod
|
@ -3,7 +3,7 @@ module go.mau.fi/mautrix-discord
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/bwmarrin/discordgo v0.25.0
|
||||
github.com/bwmarrin/discordgo v0.26.1
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/lib/pq v1.10.6
|
||||
|
@ -32,4 +32,4 @@ require (
|
|||
maunium.net/go/mauflag v1.0.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20220708141955-6445b637ad87
|
||||
replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20220913114117-bbf4447874d5
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,7 @@
|
|||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/beeper/discordgo v0.0.0-20220708141955-6445b637ad87 h1:d/pVWbHPkLk3oLDDMfn+4mu6DoyOWwj02/sup5oQpag=
|
||||
github.com/beeper/discordgo v0.0.0-20220708141955-6445b637ad87/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||
github.com/beeper/discordgo v0.0.0-20220913114117-bbf4447874d5 h1:w/mHH7KoSLUPhqW11mu2rE7cLXhW878bBVRnZ/kiIhs=
|
||||
github.com/beeper/discordgo v0.0.0-20220913114117-bbf4447874d5/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
|
|
@ -43,7 +43,7 @@ func New() (*Client, error) {
|
|||
}
|
||||
|
||||
return &Client{
|
||||
URL: "wss://remote-auth-gateway.discord.gg/?v=1",
|
||||
URL: "wss://remote-auth-gateway.discord.gg/?v=2",
|
||||
privateKey: privateKey,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
type serverPacket interface {
|
||||
|
@ -53,14 +55,19 @@ func (c *Client) processMessages() {
|
|||
dest = new(serverNonceProof)
|
||||
case "pending_remote_init":
|
||||
dest = new(serverPendingRemoteInit)
|
||||
case "pending_finish":
|
||||
dest = new(serverPendingFinish)
|
||||
case "finish":
|
||||
dest = new(serverFinish)
|
||||
case "pending_ticket":
|
||||
dest = new(serverPendingTicket)
|
||||
case "pending_login":
|
||||
dest = new(serverPendingLogin)
|
||||
case "cancel":
|
||||
dest = new(serverCancel)
|
||||
case "heartbeat_ack":
|
||||
dest = new(serverHeartbeatAck)
|
||||
default:
|
||||
c.Lock()
|
||||
c.err = fmt.Errorf("unknown op %s", raw.OP)
|
||||
c.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(packet, dest); err != nil {
|
||||
|
@ -182,11 +189,11 @@ func (p *serverPendingRemoteInit) process(client *Client) error {
|
|||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// PendingFinish
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
type serverPendingFinish struct {
|
||||
type serverPendingTicket struct {
|
||||
EncryptedUserPayload string `json:"encrypted_user_payload"`
|
||||
}
|
||||
|
||||
func (p *serverPendingFinish) process(client *Client) error {
|
||||
func (p *serverPendingTicket) process(client *Client) error {
|
||||
plaintext, err := client.decrypt(p.EncryptedUserPayload)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -198,12 +205,21 @@ func (p *serverPendingFinish) process(client *Client) error {
|
|||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Finish
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
type serverFinish struct {
|
||||
EncryptedToken string `json:"encrypted_token"`
|
||||
type serverPendingLogin struct {
|
||||
Ticket string `json:"ticket"`
|
||||
}
|
||||
|
||||
func (f *serverFinish) process(client *Client) error {
|
||||
plaintext, err := client.decrypt(f.EncryptedToken)
|
||||
func (p *serverPendingLogin) process(client *Client) error {
|
||||
sess, err := discordgo.New("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
encryptedToken, err := sess.RemoteAuthLogin(p.Ticket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
plaintext, err := client.decrypt(encryptedToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue