forked from OpenListTeam/auth
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbaidu.go
More file actions
32 lines (28 loc) · 690 Bytes
/
baidu.go
File metadata and controls
32 lines (28 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package auth
import (
"fmt"
"github.com/twoonefour/alist-auth/common"
"github.com/twoonefour/alist-auth/utils"
"github.com/gin-gonic/gin"
)
var (
baiduClientId string
baiduClientSecret string
baiduCallbackUri string
)
func baiduToken(c *gin.Context) {
code := c.Query("code")
if code == "" {
common.ErrorStr(c, "no code")
return
}
res, err := utils.RestyClient.R().
Get(fmt.Sprintf(
"https://openapi.baidu.com/oauth/2.0/token?grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s&redirect_uri=%s",
code, baiduClientId, baiduClientSecret, baiduCallbackUri))
if err != nil {
common.Error(c, err)
return
}
common.JsonBytes(c, res.Body())
}