@@ -17,12 +17,7 @@ const (
17
17
UserEndpoint = "https://connect.linux.do/api/user"
18
18
)
19
19
20
- var (
21
- ClientID = config .LinuxdoClientId
22
- ClientSecret = config .LinuxdoClientSecret
23
- RedirectURI = config .Adderss + "/oauth2/callback"
24
- store = sessions .NewCookieStore ([]byte ("secret-key" ))
25
- )
20
+ var store = sessions .NewCookieStore ([]byte ("secret-key" ))
26
21
27
22
type User struct {
28
23
ID int `json:"id"`
@@ -53,12 +48,12 @@ func initiateAuthHandler(w http.ResponseWriter, r *http.Request) {
53
48
// 构造授权 URL
54
49
authURL := fmt .Sprintf ("%s?client_id=%s&response_type=code&redirect_uri=%s&state=%s" ,
55
50
AuthorizationEndpoint ,
56
- ClientID ,
57
- RedirectURI ,
51
+ config . ClientId ,
52
+ config . Adderss + "/oauth2/callback" ,
58
53
state ,
59
54
)
60
-
61
- http .Redirect (w , r , authURL , http .StatusFound )
55
+ fmt . Printf ( "authURL: %v \n " , authURL )
56
+ // http.Redirect(w, r, authURL, http.StatusFound)
62
57
}
63
58
64
59
// 处理回调
@@ -81,12 +76,12 @@ func callbackHandler(w http.ResponseWriter, r *http.Request) {
81
76
82
77
// 请求 access token
83
78
resp , err := client .R ().
84
- SetBasicAuth (ClientID , ClientSecret ).
79
+ SetBasicAuth (config . ClientId , config . ClientSecret ).
85
80
SetHeader ("Accept" , "application/json" ).
86
81
SetFormData (map [string ]string {
87
82
"grant_type" : "authorization_code" ,
88
83
"code" : code ,
89
- "redirect_uri" : RedirectURI ,
84
+ "redirect_uri" : config . Adderss + "/oauth2/callback" ,
90
85
}).
91
86
Post (TokenEndpoint )
92
87
0 commit comments