From 1346ff2a1327414bca0cf4d8b6dba5bea27aa3fc Mon Sep 17 00:00:00 2001 From: jnanar Date: Mon, 1 Nov 2021 19:43:55 +0100 Subject: [PATCH] Support for XEP-0070 This commit allows to create a component to use 2FA authentication with XMPP. --- stanza/httauth.go | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 stanza/httauth.go diff --git a/stanza/httauth.go b/stanza/httauth.go new file mode 100644 index 0000000..c4af9c8 --- /dev/null +++ b/stanza/httauth.go @@ -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{}) +}