Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
91e5f3d9
authored
May 17, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support dummy sk- prefix for token (#82)
parent
a0923067
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
2 deletions
+2
-2
middleware/auth.go
+2
-0
model/token.go
+0
-2
No files found.
middleware/auth.go
View file @
91e5f3d9
...
...
@@ -85,6 +85,8 @@ func RootAuth() func(c *gin.Context) {
func
TokenAuth
()
func
(
c
*
gin
.
Context
)
{
return
func
(
c
*
gin
.
Context
)
{
key
:=
c
.
Request
.
Header
.
Get
(
"Authorization"
)
key
=
strings
.
TrimPrefix
(
key
,
"Bearer "
)
key
=
strings
.
TrimPrefix
(
key
,
"sk-"
)
parts
:=
strings
.
Split
(
key
,
"-"
)
key
=
parts
[
0
]
token
,
err
:=
model
.
ValidateUserToken
(
key
)
...
...
model/token.go
View file @
91e5f3d9
...
...
@@ -6,7 +6,6 @@ import (
_
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"one-api/common"
"strings"
)
type
Token
struct
{
...
...
@@ -38,7 +37,6 @@ func ValidateUserToken(key string) (token *Token, err error) {
if
key
==
""
{
return
nil
,
errors
.
New
(
"未提供 token"
)
}
key
=
strings
.
Replace
(
key
,
"Bearer "
,
""
,
1
)
token
=
&
Token
{}
err
=
DB
.
Where
(
"`key` = ?"
,
key
)
.
First
(
token
)
.
Error
if
err
==
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment