From 1fbfe32f929fa5219927e7825b2d7edbb335facb Mon Sep 17 00:00:00 2001
From: zachmann <gabriel.zachmann@kit.edu>
Date: Fri, 3 Jun 2022 12:22:40 +0200
Subject: [PATCH] fix using mytokens with form encoding

---
 CHANGELOG.md                                        | 4 ++++
 shared/mytoken/universalmytoken/universalmytoken.go | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index acc0b3a5..d3a4701a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,10 @@
 
 ## mytoken 0.4.3
 
+### Bugfixes
+
+- Fixed a bug where mytokens could not be used with x-www-form-urlencoding
+
 ### Dependencies
 
 - Bumped github.com/jmoiron/sqlx from 1.3.4 to 1.3.5
diff --git a/shared/mytoken/universalmytoken/universalmytoken.go b/shared/mytoken/universalmytoken/universalmytoken.go
index a88d853f..1721bc57 100644
--- a/shared/mytoken/universalmytoken/universalmytoken.go
+++ b/shared/mytoken/universalmytoken/universalmytoken.go
@@ -19,6 +19,13 @@ type UniversalMytoken struct {
 	OriginalTokenType model.ResponseType
 }
 
+// UnmarshalText implements the encoding.TextUnmarshaler interface
+func (t *UniversalMytoken) UnmarshalText(data []byte) (err error) {
+	s := string(data)
+	*t, err = Parse(log.StandardLogger(), s)
+	return errors.WithStack(err)
+}
+
 // UnmarshalJSON implements the json.Unmarshaler interface
 func (t *UniversalMytoken) UnmarshalJSON(data []byte) (err error) {
 	var token string
-- 
GitLab