Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 311bb0f

Browse files
committed
fix(auth): replace several default api
* fix(onedrive): replace api base * feat(115_open): 115_open oauth implement * feat(main): add main entry as backend app
1 parent dfb7515 commit 311bb0f

14 files changed

Lines changed: 949 additions & 18 deletions

File tree

115_open.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package auth
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"github.com/twoonefour/115-sdk-go"
6+
"github.com/twoonefour/alist-auth/utils"
7+
"net/http"
8+
)
9+
10+
var (
11+
clientID string
12+
)
13+
14+
type TokenReq struct {
15+
Uid string `json:"uid" binding:"required"`
16+
CodeVerifier string `json:"code_verifier" binding:"required"`
17+
}
18+
19+
func Open115Qrcode(c *gin.Context) {
20+
client := sdk.New()
21+
var cv string
22+
var resp *sdk.AuthDeviceCodeResp
23+
cv, err := utils.GenerateCodeVerifier(64)
24+
if err != nil {
25+
c.Error(err)
26+
return
27+
}
28+
resp, err = client.AuthDeviceCode(c, clientID, cv)
29+
if err != nil {
30+
c.Error(err)
31+
return
32+
}
33+
c.JSON(http.StatusOK, gin.H{
34+
"code_verifier": cv,
35+
"resp": resp,
36+
})
37+
}
38+
39+
func Open115Token(c *gin.Context) {
40+
client := sdk.New()
41+
var req TokenReq
42+
if err := c.ShouldBindJSON(&req); err != nil {
43+
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
44+
return
45+
}
46+
var codeToTokenResp *sdk.CodeToTokenResp
47+
codeToTokenResp, err := client.CodeToToken(c, req.Uid, req.CodeVerifier)
48+
if err != nil {
49+
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
50+
return
51+
}
52+
c.JSON(http.StatusOK, gin.H{"resp": codeToTokenResp})
53+
}

ali.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package alist
1+
package auth
22

33
import (
4-
"api.nn.ci/apps/common"
5-
"api.nn.ci/utils"
64
"github.com/gin-gonic/gin"
5+
"github.com/twoonefour/alist-auth/common"
6+
"github.com/twoonefour/alist-auth/utils"
77
)
88

99
func Qr(c *gin.Context) {
@@ -64,9 +64,9 @@ func Ck(c *gin.Context) {
6464
"referer": "https://passport.aliyundrive.com/mini_login.htm?&appName=aliyun_drive",
6565
}).
6666
Post("https://passport.aliyundrive.com/newlogin/qrcode/query.do?appName=aliyun_drive&fromSite=52&_bx-v=2.0.31")
67-
//data := utils.Json.Get(res.Body(), "content", "data")
68-
//loginResult := data.Get("loginResult").ToString()
69-
//bizExt := data.Get("bizExt").ToString()
67+
// data := utils.Json.Get(res.Body(), "content", "data")
68+
// loginResult := data.Get("loginResult").ToString()
69+
// bizExt := data.Get("bizExt").ToString()
7070
c.Header("Content-Type", "application/json")
7171
c.Writer.Write(res.Body())
7272
}

ali_open.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package alist
1+
package auth
22

33
import (
44
"fmt"
5+
"github.com/twoonefour/alist-auth/common"
6+
"github.com/twoonefour/alist-auth/utils"
57
"strings"
68

7-
"api.nn.ci/apps/common"
8-
"api.nn.ci/utils"
99
"github.com/gin-gonic/gin"
1010
)
1111

baidu.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package alist
1+
package auth
22

33
import (
44
"fmt"
5+
"github.com/twoonefour/alist-auth/common"
6+
"github.com/twoonefour/alist-auth/utils"
57

6-
"api.nn.ci/apps/common"
7-
"api.nn.ci/utils"
88
"github.com/gin-gonic/gin"
99
)
1010

1111
var (
1212
baiduClientId string
1313
baiduClientSecret string
14-
baiduCallbackUri = "https://alist.nn.ci/tool/baidu/callback"
14+
baiduCallbackUri string
1515
)
1616

1717
func baiduToken(c *gin.Context) {

cmd/alist-oauth2/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
auth "github.com/twoonefour/alist-auth"
6+
"github.com/twoonefour/alist-auth/utils"
7+
)
8+
9+
func main() {
10+
r := gin.New()
11+
r.Use(utils.LoggerMiddleware())
12+
api := r.Group("/alist")
13+
auth.Setup(api)
14+
r.Run(":3002")
15+
}

common/error.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package common
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gin-gonic/gin"
7+
"log"
8+
)
9+
10+
type Response struct {
11+
Code int `json:"code"`
12+
Message string `json:"message"`
13+
Data interface{} `json:"data"`
14+
}
15+
16+
func Error(c *gin.Context, err error) {
17+
log.Printf("[ERROR] %v\n", err)
18+
c.AbortWithStatusJSON(http.StatusInternalServerError, Response{
19+
Code: http.StatusInternalServerError,
20+
Message: err.Error(),
21+
})
22+
}
23+
24+
func ErrorStr(c *gin.Context, message string) {
25+
c.AbortWithStatusJSON(http.StatusInternalServerError, Response{
26+
Code: http.StatusInternalServerError,
27+
Message: message,
28+
})
29+
}
30+
31+
func ErrorJson(c *gin.Context, err interface{}, code ...int) {
32+
c.AbortWithStatusJSON(http.StatusInternalServerError, Response{
33+
Code: func() int {
34+
if len(code) > 0 {
35+
return code[0]
36+
}
37+
return http.StatusInternalServerError
38+
}(),
39+
Data: err,
40+
})
41+
}

common/json.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package common
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
)
6+
7+
func JsonBytes(c *gin.Context, jsonBytes []byte) error {
8+
c.Header("Content-Type", "application/json; charset=utf-8")
9+
c.Header("Access-Control-Allow-Origin", "*")
10+
c.Header("Access-Control-Allow-Methods", "POST, OPTIONS")
11+
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
12+
c.Writer.WriteHeaderNow()
13+
if _, err := c.Writer.Write(jsonBytes); err != nil {
14+
return err
15+
}
16+
return nil
17+
}

go.mod

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module github.com/twoonefour/alist-auth
2+
3+
go 1.24.0
4+
5+
require (
6+
github.com/axiaoxin-com/ratelimiter v1.0.3
7+
github.com/gin-gonic/gin v1.10.1
8+
github.com/go-resty/resty/v2 v2.16.5
9+
github.com/sirupsen/logrus v1.4.2
10+
github.com/twoonefour/115-sdk-go v0.1.5
11+
)
12+
13+
require (
14+
github.com/axiaoxin-com/logging v1.2.3 // indirect
15+
github.com/beorn7/perks v1.0.1 // indirect
16+
github.com/bytedance/sonic v1.13.2 // indirect
17+
github.com/bytedance/sonic/loader v0.2.4 // indirect
18+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
19+
github.com/cloudwego/base64x v0.1.5 // indirect
20+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
21+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
22+
github.com/getsentry/sentry-go v0.6.0 // indirect
23+
github.com/gin-contrib/sse v1.0.0 // indirect
24+
github.com/go-playground/locales v0.14.1 // indirect
25+
github.com/go-playground/universal-translator v0.18.1 // indirect
26+
github.com/go-playground/validator/v10 v10.26.0 // indirect
27+
github.com/go-redis/redis/v8 v8.0.0-beta.10 // indirect
28+
github.com/goccy/go-json v0.10.5 // indirect
29+
github.com/golang/protobuf v1.5.0 // indirect
30+
github.com/jinzhu/gorm v1.9.12 // indirect
31+
github.com/jinzhu/inflection v1.0.0 // indirect
32+
github.com/json-iterator/go v1.1.12 // indirect
33+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
34+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
35+
github.com/leodido/go-urn v1.4.0 // indirect
36+
github.com/mattn/go-isatty v0.0.20 // indirect
37+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
38+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
39+
github.com/modern-go/reflect2 v1.0.2 // indirect
40+
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
41+
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
42+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
43+
github.com/prometheus/client_golang v1.7.1 // indirect
44+
github.com/prometheus/client_model v0.2.0 // indirect
45+
github.com/prometheus/common v0.10.0 // indirect
46+
github.com/prometheus/procfs v0.1.3 // indirect
47+
github.com/rs/xid v1.2.1 // indirect
48+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
49+
github.com/ugorji/go/codec v1.2.12 // indirect
50+
github.com/xhofe/115-sdk-go v0.1.5 // indirect
51+
go.opentelemetry.io/otel v0.11.0 // indirect
52+
go.uber.org/multierr v1.11.0 // indirect
53+
go.uber.org/zap v1.27.0 // indirect
54+
golang.org/x/arch v0.15.0 // indirect
55+
golang.org/x/crypto v0.36.0 // indirect
56+
golang.org/x/exp v0.0.0-20200821190819-94841d0725da // indirect
57+
golang.org/x/net v0.38.0 // indirect
58+
golang.org/x/sys v0.31.0 // indirect
59+
golang.org/x/text v0.23.0 // indirect
60+
golang.org/x/time v0.6.0 // indirect
61+
google.golang.org/protobuf v1.36.6 // indirect
62+
gopkg.in/yaml.v3 v3.0.1 // indirect
63+
resty.dev/v3 v3.0.0-beta.1 // indirect
64+
)

0 commit comments

Comments
 (0)