:feature: 添加获取请求协议的函数,优化Logto登录和登出URL构建
All checks were successful
BuildImage / build-image (push) Successful in 8m52s
All checks were successful
BuildImage / build-image (push) Successful in 8m52s
This commit is contained in:
parent
8a02f2f175
commit
8c11c0375a
@ -2,6 +2,7 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitee.ltd/lxh/wechat-robot/internal/types"
|
"gitee.ltd/lxh/wechat-robot/internal/types"
|
||||||
@ -21,6 +22,23 @@ var store = session.New(session.Config{
|
|||||||
// 可以配置 CookieSecret
|
// 可以配置 CookieSecret
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// getProtocol
|
||||||
|
// @description: 获取请求协议
|
||||||
|
// @param c
|
||||||
|
// @return string
|
||||||
|
func getProtocol(c *fiber.Ctx) string {
|
||||||
|
protocol := c.Protocol()
|
||||||
|
for k, v := range c.GetReqHeaders() {
|
||||||
|
if strings.ToLower(k) == "referer" {
|
||||||
|
refererProtocol := strings.Split(v[0], ":")[0]
|
||||||
|
if refererProtocol != protocol {
|
||||||
|
protocol = refererProtocol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return protocol
|
||||||
|
}
|
||||||
|
|
||||||
// LogtoLogin 重定向到Logto登录页面
|
// LogtoLogin 重定向到Logto登录页面
|
||||||
func LogtoLogin(c *fiber.Ctx) error {
|
func LogtoLogin(c *fiber.Ctx) error {
|
||||||
// 加载配置
|
// 加载配置
|
||||||
@ -30,7 +48,8 @@ func LogtoLogin(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构建回调URL
|
// 构建回调URL
|
||||||
callbackURL := c.Protocol() + "://" + c.Hostname() + "/auth/logto/callback"
|
|
||||||
|
callbackURL := getProtocol(c) + "://" + c.Hostname() + "/auth/logto/callback"
|
||||||
|
|
||||||
// 创建Logto客户端配置
|
// 创建Logto客户端配置
|
||||||
logtoConfig := &logtoClient.LogtoConfig{
|
logtoConfig := &logtoClient.LogtoConfig{
|
||||||
@ -121,7 +140,7 @@ func LogtoLogout(c *fiber.Ctx) error {
|
|||||||
client := logtoClient.NewLogtoClient(logtoConfig, fiberSessionStorage)
|
client := logtoClient.NewLogtoClient(logtoConfig, fiberSessionStorage)
|
||||||
|
|
||||||
// 构建登出后重定向URL
|
// 构建登出后重定向URL
|
||||||
postLogoutRedirectURL := c.Protocol() + "://" + c.Hostname()
|
postLogoutRedirectURL := getProtocol(c) + "://" + c.Hostname()
|
||||||
|
|
||||||
// 获取登出链接
|
// 获取登出链接
|
||||||
signOutUri, err := client.SignOut(postLogoutRedirectURL)
|
signOutUri, err := client.SignOut(postLogoutRedirectURL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user