Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10433295
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/auth/auth.go b/auth/auth.go
new file mode 100644
index 0000000..868897c
--- /dev/null
+++ b/auth/auth.go
@@ -0,0 +1,43 @@
+package auth
+
+import (
+ uuid "github.com/nu7hatch/gouuid"
+ "github.com/writeas/web-core/log"
+ "strings"
+)
+
+// GetToken parses out the user token from either an Authorization header or simply passed in.
+func GetToken(header string) []byte {
+ var accessToken []byte
+ token := header
+ if len(header) > 0 {
+ f := strings.Fields(header)
+ if len(f) == 2 && f[0] == "Token" {
+ token = f[1]
+ }
+ }
+ t, err := uuid.ParseHex(token)
+ if err != nil {
+ log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
+ } else {
+ accessToken = t[:]
+ }
+ return accessToken
+}
+
+// GetHeaderToken parses out the user token from an Authorization header.
+func GetHeaderToken(header string) []byte {
+ var accessToken []byte
+ if len(header) > 0 {
+ f := strings.Fields(header)
+ if len(f) == 2 && f[0] == "Token" {
+ t, err := uuid.ParseHex(f[1])
+ if err != nil {
+ log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
+ } else {
+ accessToken = t[:]
+ }
+ }
+ }
+ return accessToken
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Jan 20, 2:40 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3137533
Attached To
rWC Write.as Web Core
Event Timeline
Log In to Comment