Accepts token in querystring

This commit is contained in:
LittleSheep 2024-06-22 20:28:58 +08:00
parent d654931483
commit 4537bc9f28
3 changed files with 13 additions and 7 deletions

11
.idea/workspace.xml generated
View File

@ -4,10 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":recycle: Improve code structure and much easier to read&#10;:bug: Fix auth middleware"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: FIx cannot resolve service">
<change beforePath="$PROJECT_DIR$/pkg/hyper/conn.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/hyper/conn.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/admin/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/admin/index.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/hyper/auth_adaptor.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/hyper/auth_adaptor.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/ui/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/ui/index.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -144,7 +143,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":bug: Bug fixes on E2EE" />
<MESSAGE value=":bug: Fix key exchange cause echo" /> <MESSAGE value=":bug: Fix key exchange cause echo" />
<MESSAGE value=":bug: Fix notification push issue" /> <MESSAGE value=":bug: Fix notification push issue" />
<MESSAGE value=":sparkles: Basis perm nodes feature" /> <MESSAGE value=":sparkles: Basis perm nodes feature" />
@ -169,7 +167,8 @@
<MESSAGE value=":sparkles: Drop direct connection and uses consul" /> <MESSAGE value=":sparkles: Drop direct connection and uses consul" />
<MESSAGE value=":technologist: Add the server side Hyper SDK" /> <MESSAGE value=":technologist: Add the server side Hyper SDK" />
<MESSAGE value=":recycle: Improve code structure and much easier to read&#10;:bug: Fix auth middleware" /> <MESSAGE value=":recycle: Improve code structure and much easier to read&#10;:bug: Fix auth middleware" />
<option name="LAST_COMMIT_MESSAGE" value=":recycle: Improve code structure and much easier to read&#10;:bug: Fix auth middleware" /> <MESSAGE value=":bug: FIx cannot resolve service" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: FIx cannot resolve service" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

View File

@ -20,10 +20,14 @@ func (v *HyperConn) AuthMiddleware(c *fiber.Ctx) error {
tk := strings.Replace(header, "Bearer", "", 1) tk := strings.Replace(header, "Bearer", "", 1)
atk = strings.TrimSpace(tk) atk = strings.TrimSpace(tk)
} }
if tk := c.Query("tk"); len(tk) > 0 {
atk = strings.TrimSpace(tk)
}
c.Locals("p_token", atk) c.Locals("p_token", atk)
if user, newAtk, newRtk, err := v.DoAuthenticate(atk, c.Cookies(CookieRtk)); err == nil { rtk := c.Cookies(CookieRtk)
if user, newAtk, newRtk, err := v.DoAuthenticate(atk, rtk); err == nil {
if newAtk != atk { if newAtk != atk {
c.Cookie(&fiber.Cookie{ c.Cookie(&fiber.Cookie{
Name: CookieAtk, Name: CookieAtk,

View File

@ -18,6 +18,9 @@ func AuthMiddleware(c *fiber.Ctx) error {
tk := strings.Replace(header, "Bearer", "", 1) tk := strings.Replace(header, "Bearer", "", 1)
atk = strings.TrimSpace(tk) atk = strings.TrimSpace(tk)
} }
if tk := c.Query("tk"); len(tk) > 0 {
atk = strings.TrimSpace(tk)
}
c.Locals("p_token", atk) c.Locals("p_token", atk)