Files
upstream-corteza/server/auth/handlers/links.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

123 lines
2.8 KiB
Go

package handlers
import (
"regexp"
"strings"
)
type (
Links struct {
Profile,
Signup,
ConfirmEmail,
PendingEmailConfirmation,
Login,
Security,
ChangePassword,
CreatePassword,
RequestPasswordReset,
PasswordResetRequested,
ResetPassword,
AcceptInvite,
Sessions,
AuthorizedClients,
Logout,
OAuth2Authorize,
OAuth2AuthorizeClient,
OAuth2Token,
OAuth2Info,
OAuth2UserInfo,
OAuth2DefaultClient,
OAuth2PublicKeys,
Mfa,
MfaTotpNewSecret,
MfaTotpQRImage,
MfaTotpDisable,
External,
SamlInit,
SamlCallback,
SamlMetadata,
SamlLogout,
Base,
Assets,
AuthAssets string
}
)
var (
invalidLinkChars = regexp.MustCompile(`[^-A-Za-z0-9+&@#/%?=~_|!:,.;\\(\\)]`)
stripSchema = regexp.MustCompile(`(.*\/\/)`)
BasePath string = "/"
WebappBasePath string = "/"
)
func GetLinks() Links {
var b = strings.TrimSuffix(BasePath, "/") + "/"
return Links{
Profile: b + "auth",
Signup: b + "auth/signup",
ConfirmEmail: b + "auth/confirm-email",
PendingEmailConfirmation: b + "auth/pending-email-confirmation",
Login: b + "auth/login",
Security: b + "auth/security",
ChangePassword: b + "auth/change-password",
CreatePassword: b + "auth/create-password",
RequestPasswordReset: b + "auth/request-password-reset",
PasswordResetRequested: b + "auth/password-reset-requested",
ResetPassword: b + "auth/reset-password",
AcceptInvite: b + "auth/accept-invite",
Sessions: b + "auth/sessions",
AuthorizedClients: b + "auth/authorized-clients",
Logout: b + "auth/logout",
OAuth2Authorize: b + "auth/oauth2/authorize",
OAuth2AuthorizeClient: b + "auth/oauth2/authorize-client",
OAuth2Token: b + "auth/oauth2/token",
OAuth2Info: b + "auth/oauth2/info",
OAuth2UserInfo: b + "auth/oauth2/userinfo",
OAuth2DefaultClient: b + "auth/oauth2/default-client",
OAuth2PublicKeys: b + "auth/oauth2/public-keys",
Mfa: b + "auth/mfa",
MfaTotpNewSecret: b + "auth/mfa/totp/setup",
MfaTotpQRImage: b + "auth/mfa/totp/qr.png",
MfaTotpDisable: b + "auth/mfa/totp/disable",
External: b + "auth/external",
SamlInit: b + "auth/external/saml/init",
SamlCallback: b + "auth/external/saml/callback",
SamlMetadata: b + "auth/external/saml/metadata",
SamlLogout: b + "auth/external/saml/slo",
Assets: b + "assets",
AuthAssets: b + "auth/assets/public",
Base: b,
}
}
// trim base path
func tbp(s string) string {
s = strings.TrimPrefix(s, BasePath)
if !strings.HasPrefix(s, "/") {
s = "/" + s
}
return s
}
func sanitizeLink(l string) string {
return `//` + stripSchema.ReplaceAllString(invalidLinkChars.ReplaceAllString(l, ""), "")
}