snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
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
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
This commit is contained in:
109
server/auth/commands/assets.go
Normal file
109
server/auth/commands/assets.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/auth"
|
||||
"github.com/cortezaproject/corteza/server/pkg/cli"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func assets(app serviceInitializer) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "assets",
|
||||
Short: "Authentication flow assets (styling, images) and templates",
|
||||
}
|
||||
|
||||
exportCmd := &cobra.Command{
|
||||
Use: "export",
|
||||
Short: "Exports embedded assets into provided path (must exists)",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
assetsRoot := app.Options().Auth.AssetsPath
|
||||
if len(args) > 0 {
|
||||
assetsRoot = args[0]
|
||||
}
|
||||
|
||||
if len(assetsRoot) == 0 {
|
||||
cmd.Println("can not export, no path provided and AUTH_ASSETS_PATH is empty")
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := os.Stat(assetsRoot); err != nil {
|
||||
cli.HandleError(err)
|
||||
}
|
||||
|
||||
emb := map[string]embed.FS{
|
||||
"public": auth.PublicAssets,
|
||||
"templates": auth.Templates,
|
||||
}
|
||||
|
||||
var (
|
||||
fh *os.File
|
||||
buf []byte
|
||||
dst string
|
||||
src string
|
||||
assetsSub string
|
||||
)
|
||||
for dir, efs := range emb {
|
||||
assetsSub = path.Join(assetsRoot, dir)
|
||||
|
||||
cmd.Printf("exporting auth assets to %s\n", dir)
|
||||
if _, err := os.Stat(assetsSub); os.IsNotExist(err) {
|
||||
cli.HandleError(os.Mkdir(assetsSub, 0755))
|
||||
cmd.Println("directory created")
|
||||
} else if err != nil {
|
||||
cli.HandleError(err)
|
||||
}
|
||||
|
||||
cc, err := efs.ReadDir(path.Join("assets", dir))
|
||||
if err != nil {
|
||||
cli.HandleError(err)
|
||||
}
|
||||
|
||||
for _, c := range cc {
|
||||
src = path.Join("assets", dir, c.Name())
|
||||
dst = path.Join(assetsSub, c.Name())
|
||||
|
||||
if c.IsDir() {
|
||||
cmd.Println("skipping directory:", assetsRoot)
|
||||
continue
|
||||
}
|
||||
|
||||
cmd.Print("exporting asset ", dst, ": ")
|
||||
|
||||
buf, err = efs.ReadFile(src)
|
||||
if err != nil {
|
||||
cmd.Println("\n => error:", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
fh, err = os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666)
|
||||
if os.IsExist(err) {
|
||||
cmd.Println("exists")
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
cmd.Println("\n => error:", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = fh.Write(buf)
|
||||
if err != nil {
|
||||
cmd.Println("\n => error:", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
cmd.Println("ok")
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
cmd.AddCommand(exportCmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
184
server/auth/commands/commands.go
Normal file
184
server/auth/commands/commands.go
Normal file
@@ -0,0 +1,184 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/auth/external"
|
||||
"github.com/cortezaproject/corteza/server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza/server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza/server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza/server/pkg/options"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type (
|
||||
serviceInitializer interface {
|
||||
InitServices(ctx context.Context) error
|
||||
Activate(ctx context.Context) error
|
||||
Options() *options.Options
|
||||
}
|
||||
)
|
||||
|
||||
func commandPreRunInitService(app serviceInitializer) func(*cobra.Command, []string) error {
|
||||
return func(_ *cobra.Command, _ []string) error {
|
||||
return app.InitServices(cli.Context())
|
||||
}
|
||||
}
|
||||
|
||||
func commandPreRunInitActivate(app serviceInitializer) func(*cobra.Command, []string) error {
|
||||
return func(_ *cobra.Command, _ []string) error {
|
||||
return app.Activate(cli.Context())
|
||||
}
|
||||
}
|
||||
|
||||
func Command(ctx context.Context, app serviceInitializer, storeInit func(ctx context.Context) (store.Storer, error)) *cobra.Command {
|
||||
var (
|
||||
enableDiscoveredProvider bool
|
||||
skipValidationOnAutoDiscoveredProvider bool
|
||||
|
||||
clientID uint64
|
||||
scope []string
|
||||
tokenDuration time.Duration
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "auth",
|
||||
Short: "Authentication management",
|
||||
}
|
||||
|
||||
autoDiscoverCmd := &cobra.Command{
|
||||
Use: "auto-discovery [name] [url]",
|
||||
Short: "Auto discovers new OIDC client",
|
||||
Args: cobra.ExactArgs(2),
|
||||
PreRunE: commandPreRunInitService(app),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := cli.Context()
|
||||
|
||||
s, err := storeInit(ctx)
|
||||
cli.HandleError(err)
|
||||
|
||||
_, err = external.RegisterOidcProvider(
|
||||
ctx,
|
||||
logger.Default(),
|
||||
s,
|
||||
app.Options().Auth,
|
||||
args[0],
|
||||
args[1],
|
||||
true,
|
||||
!skipValidationOnAutoDiscoveredProvider,
|
||||
enableDiscoveredProvider,
|
||||
)
|
||||
|
||||
cli.HandleError(err)
|
||||
|
||||
if enableDiscoveredProvider {
|
||||
cmd.Println("OIDC provider successfully added and enabled.")
|
||||
} else {
|
||||
cmd.Println("OIDC provider successfully added (still disabled).")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
autoDiscoverCmd.Flags().BoolVar(
|
||||
&enableDiscoveredProvider,
|
||||
"enable",
|
||||
false,
|
||||
"Enable this provider and external auth")
|
||||
|
||||
autoDiscoverCmd.Flags().BoolVar(
|
||||
&skipValidationOnAutoDiscoveredProvider,
|
||||
"skip-validation",
|
||||
false,
|
||||
"Skip validation")
|
||||
|
||||
jwtCmd := &cobra.Command{
|
||||
Use: "jwt [email-or-id]",
|
||||
Short: "Generates new JWT for a user",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
PreRunE: commandPreRunInitService(app),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.ServiceUser())
|
||||
var (
|
||||
signedToken []byte
|
||||
user *types.User
|
||||
err error
|
||||
|
||||
userStr = args[0]
|
||||
)
|
||||
|
||||
user, err = service.DefaultUser.FindByAny(ctx, userStr)
|
||||
cli.HandleError(err)
|
||||
|
||||
err = service.DefaultAuth.LoadRoleMemberships(ctx, user)
|
||||
cli.HandleError(err)
|
||||
|
||||
opts := []auth.IssueOptFn{
|
||||
auth.WithIdentity(user),
|
||||
auth.WithScope(scope...),
|
||||
}
|
||||
|
||||
if clientID > 0 {
|
||||
opts = append(opts, auth.WithClientID(clientID))
|
||||
}
|
||||
|
||||
if tokenDuration > 0 {
|
||||
opts = append(opts, auth.WithExpiration(tokenDuration))
|
||||
}
|
||||
|
||||
signedToken, err = auth.TokenIssuer.Issue(ctx, opts...)
|
||||
|
||||
cli.HandleError(err)
|
||||
cmd.Println(string(signedToken))
|
||||
},
|
||||
}
|
||||
|
||||
jwtCmd.Flags().Uint64Var(
|
||||
&clientID,
|
||||
"auth-client",
|
||||
0,
|
||||
"ID if the auth client")
|
||||
|
||||
jwtCmd.Flags().StringArrayVar(
|
||||
&scope,
|
||||
"scope",
|
||||
[]string{"profile", "api"},
|
||||
"Scope")
|
||||
|
||||
jwtCmd.Flags().DurationVar(
|
||||
&tokenDuration,
|
||||
"duration",
|
||||
app.Options().Auth.AccessTokenLifetime,
|
||||
"Token expiry duration")
|
||||
|
||||
testEmails := &cobra.Command{
|
||||
Use: "test-notifications [recipient]",
|
||||
Short: "Sends samples of all authentication notification to recipient",
|
||||
Args: cobra.ExactArgs(1),
|
||||
PreRunE: commandPreRunInitActivate(app),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
err error
|
||||
ntf = service.DefaultAuthNotification
|
||||
)
|
||||
|
||||
// Update current settings to be sure that we do not have outdated values
|
||||
cli.HandleError(service.DefaultSettings.UpdateCurrent(ctx))
|
||||
|
||||
err = ntf.PasswordReset(ctx, args[0], "notification-testing-token")
|
||||
cli.HandleError(err)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
autoDiscoverCmd,
|
||||
testEmails,
|
||||
jwtCmd,
|
||||
assets(app),
|
||||
)
|
||||
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user