| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // signinURL returns the sign-in route, carrying the current tenant-local |
| 9 | // address so the signer can return the viewer to the page they opened. |
| 10 | // Fragments are intentionally absent here because browsers do not send them |
| 11 | // in HTTP requests; client-side navigation may preserve one when present. |
| 12 | func signinURL(base, path string, query url.Values) string { |
| 13 | path = "/" + strings.TrimPrefix(path, "/" ) |
| 14 | if path == "/signin" { |
| 15 | return path |
| 16 | } |
| 17 | if base != "" && base != "/" { |
| 18 | path = joinTenantPath(base, path) |
| 19 | } |
| 20 | if encoded := query.Encode(); encoded != "" { |
| 21 | path += "?" + encoded |
| 22 | } |
| 23 | return "/signin?next=" + url.QueryEscape(path) |
| 24 | } |
| 25 | |
| 26 | func joinTenantPath(base, path string) string { |
| 27 | base = strings.TrimSuffix("/" +strings.Trim(base, "/" ), "/" ) |
| 28 | if base == "/" { |
| 29 | return "/" + strings.TrimPrefix(path, "/" ) |
| 30 | } |
| 31 | return base + "/" + strings.TrimPrefix(path, "/" ) |
| 32 | } |