Merge branch 'refs/heads/feat-login-website'
This commit is contained in:
commit
a083b5eed1
|
|
@ -4,6 +4,7 @@
|
||||||
<inspection_tool class="GoDfaErrorMayBeNotNil" enabled="true" level="WARNING" enabled_by_default="true">
|
<inspection_tool class="GoDfaErrorMayBeNotNil" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
<functions>
|
<functions>
|
||||||
<function importPath="net/http" name="NewRequest" />
|
<function importPath="net/http" name="NewRequest" />
|
||||||
|
<function importPath="StuAcaWorksAI/worker" name="GetStackoverflowAccessTokenByCode" />
|
||||||
</functions>
|
</functions>
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
|
||||||
|
|
@ -548,32 +548,33 @@ func DoFaceBookCallBack(state *proto.ThirdPartyLoginState, code string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoStackoverflowCallBack(state *proto.ThirdPartyLoginState, code string) {
|
func DoStackoverflowCallBack(state *proto.ThirdPartyLoginState, code string) {
|
||||||
|
var thirdPartyLoginStatus proto.ThirdPartyLoginStatus
|
||||||
|
var userInfo proto.StackoverflowUserInfo
|
||||||
|
thirdPartyLoginStatus.Type = state.Platform
|
||||||
//根据code获取Access Token
|
//根据code获取Access Token
|
||||||
tokenResp, err := worker.GetStackoverflowAccessTokenByCode(code, "https://pm.ljsea.top/tool/third_party_callback", worker.StackOverflowClientID, worker.StackOverflowClientSecret)
|
tokenResp, err := worker.GetStackoverflowAccessTokenByCode(code, "https://pm.ljsea.top/tool/third_party_callback", worker.StackOverflowClientID, worker.StackOverflowClientSecret)
|
||||||
|
|
||||||
if tokenResp.AccessToken == "" {
|
if tokenResp.AccessToken == "" {
|
||||||
log.Println("get Stackoverflow access token is empty")
|
log.Println("get Stackoverflow access token is empty")
|
||||||
return
|
thirdPartyLoginStatus.Status = proto.ParameterError
|
||||||
}
|
} else {
|
||||||
log.Println("get Stackoverflow access token:", tokenResp)
|
log.Println("get Stackoverflow access token:", tokenResp)
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
userInfoResp, err := worker.GetStackoverflowUserInfo(tokenResp.AccessToken)
|
userInfoResp, err2 := worker.GetStackoverflowUserInfo(tokenResp.AccessToken)
|
||||||
if err != nil {
|
if err2 != nil {
|
||||||
log.Println("get Stackoverflow user info error:", err)
|
log.Println("get Stackoverflow user info error:", err)
|
||||||
return
|
thirdPartyLoginStatus.Status = proto.ParameterError
|
||||||
}
|
} else {
|
||||||
log.Println("get Stackoverflow user info:", userInfoResp)
|
log.Println("get Stackoverflow user info:", userInfoResp)
|
||||||
var userInfo proto.StackoverflowUserInfo
|
|
||||||
if userInfoResp.Items != nil && len(userInfoResp.Items) > 0 {
|
if userInfoResp.Items != nil && len(userInfoResp.Items) > 0 {
|
||||||
userInfo = userInfoResp.Items[0]
|
userInfo = userInfoResp.Items[0]
|
||||||
} else {
|
|
||||||
log.Println("get Stackoverflow user info is empty")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var thirdPartyLoginStatus proto.ThirdPartyLoginStatus
|
|
||||||
thirdPartyLoginStatus.Type = state.Platform
|
|
||||||
thirdPartyUserInfo := proto.ThirdPartyUserInfo{UserID: strconv.Itoa(userInfo.UserID), Name: userInfo.DisplayName, Avatar: userInfo.ProfileImage, Email: ""}
|
thirdPartyUserInfo := proto.ThirdPartyUserInfo{UserID: strconv.Itoa(userInfo.UserID), Name: userInfo.DisplayName, Avatar: userInfo.ProfileImage, Email: ""}
|
||||||
HandleThirdPartyLoginStatusV2(state, &thirdPartyLoginStatus, &thirdPartyUserInfo)
|
HandleThirdPartyLoginStatusV2(state, &thirdPartyLoginStatus, &thirdPartyUserInfo)
|
||||||
|
} else {
|
||||||
|
log.Println("get Stackoverflow user info is empty")
|
||||||
|
thirdPartyLoginStatus.Status = proto.ParameterError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//更新redis中的第三方登录状态
|
//更新redis中的第三方登录状态
|
||||||
thirdPartyLoginStatusStr, _ := json.Marshal(thirdPartyLoginStatus)
|
thirdPartyLoginStatusStr, _ := json.Marshal(thirdPartyLoginStatus)
|
||||||
log.Println("do handle Stackoverflow callback success, third party login status:", string(thirdPartyLoginStatusStr))
|
log.Println("do handle Stackoverflow callback success, third party login status:", string(thirdPartyLoginStatusStr))
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,7 @@ func GetFaceBookUserInfo(accessToken string) (proto.FaceBookUserInfoResp, error)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StackOverflowClientID = "32093"
|
StackOverflowClientID = "32093"
|
||||||
StackOverflowClientSecret = "cgHOI0emSLU7VB7jpAY9NQ(("
|
StackOverflowClientSecret = "SOvAmbfCBeei1ikqH4IwNA(("
|
||||||
StackOverflowKey = "rl_s6vbPNPhbFbMcyWp7YbaTeg18"
|
StackOverflowKey = "rl_s6vbPNPhbFbMcyWp7YbaTeg18"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue