Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10528925
auth.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
981 B
Subscribers
None
auth.go
View Options
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/plain
Expires
Sun, Apr 6, 6:50 AM (6 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3187607
Attached To
rWC Write.as Web Core
Event Timeline
Log In to Comment