Skip to content

Commit

Permalink
Support for XEP-0070
Browse files Browse the repository at this point in the history
This commit allows to create a component to use 2FA authentication with XMPP.
  • Loading branch information
jarobase committed Sep 11, 2022
1 parent 5f99e1c commit 1346ff2
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions stanza/httauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package stanza

import (
"encoding/xml"
)

// XEP-0070: Verifying HTTP Requests via XMPP
type ConfirmPayload struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/http-auth confirm"`
ID string `xml:"id,attr"`
Method string `xml:"method,attr"`
URL string `xml:"url,attr"`
}

func (c ConfirmPayload) Namespace() string {
return c.XMLName.Space
}

func (c ConfirmPayload) GetSet() *ResultSet {
return nil
}

// ---------------
// Builder helpers

// Confirm builds a default confirm payload
func (iq *IQ) Confirm() *ConfirmPayload {
d := ConfirmPayload{
XMLName: xml.Name{Space: "http://jabber.org/protocol/http-auth", Local: "confirm"},
}
iq.Payload = &d
return &d
}

// Set all confirm info
func (v *ConfirmPayload) SetConfirm(id, method, url string) *ConfirmPayload {
v.ID = id
v.Method = method
v.URL = url
return v
}

func init() {
TypeRegistry.MapExtension(PKTMessage,
xml.Name{Space: "http://jabber.org/protocol/http-auth", Local: "confirm"},
ConfirmPayload{})
TypeRegistry.MapExtension(PKTIQ,
xml.Name{Space: "http://jabber.org/protocol/http-auth", Local: "confirm"},
ConfirmPayload{})
}

0 comments on commit 1346ff2

Please sign in to comment.