mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-02-27 11:21:59 +00:00
feat: add oidc client create command
This commit is contained in:
38
cmd/tinyauth/create_oidc_client.go
Normal file
38
cmd/tinyauth/create_oidc_client.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/steveiliop56/tinyauth/internal/utils"
|
||||
"github.com/steveiliop56/tinyauth/internal/utils/tlog"
|
||||
"github.com/traefik/paerser/cli"
|
||||
)
|
||||
|
||||
func createOidcClientCmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "create",
|
||||
Description: "Create a new OIDC Client",
|
||||
Configuration: nil,
|
||||
Resources: nil,
|
||||
AllowArg: true,
|
||||
Run: func(args []string) error {
|
||||
tlog.NewSimpleLogger().Init()
|
||||
|
||||
if len(args) == 0 {
|
||||
tlog.App.Fatal().Msg("Client name is required. Use tinyauth oidc create <name>")
|
||||
}
|
||||
|
||||
clientName := args[0]
|
||||
|
||||
uuid := uuid.New()
|
||||
clientId := uuid.String()
|
||||
clientSecret := "ta-" + utils.GenerateString(61)
|
||||
|
||||
fmt.Printf("Client Name: %s\n", clientName)
|
||||
fmt.Printf("Client ID: %s\n", clientId)
|
||||
fmt.Printf("Client Secret: %s\n", clientSecret)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func main() {
|
||||
|
||||
cmdTinyauth := &cli.Command{
|
||||
Name: "tinyauth",
|
||||
Description: "The simplest way to protect your apps with a login screen.",
|
||||
Description: "The simplest way to protect your apps with a login screen",
|
||||
Configuration: tConfig,
|
||||
Resources: loaders,
|
||||
Run: func(_ []string) error {
|
||||
@@ -33,12 +33,17 @@ func main() {
|
||||
|
||||
cmdUser := &cli.Command{
|
||||
Name: "user",
|
||||
Description: "Utilities for creating and verifying Tinyauth users.",
|
||||
Description: "Manage Tinyauth users",
|
||||
}
|
||||
|
||||
cmdTotp := &cli.Command{
|
||||
Name: "totp",
|
||||
Description: "Utilities for creating Tinyauth TOTP users.",
|
||||
Description: "Manage Tinyauth TOTP users",
|
||||
}
|
||||
|
||||
cmdOidc := &cli.Command{
|
||||
Name: "oidc",
|
||||
Description: "Manage Tinyauth OIDC clients",
|
||||
}
|
||||
|
||||
err := cmdTinyauth.AddCommand(versionCmd())
|
||||
@@ -71,6 +76,12 @@ func main() {
|
||||
log.Fatal().Err(err).Msg("Failed to add create command")
|
||||
}
|
||||
|
||||
err = cmdOidc.AddCommand(createOidcClientCmd())
|
||||
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to add create command")
|
||||
}
|
||||
|
||||
err = cmdTinyauth.AddCommand(cmdUser)
|
||||
|
||||
if err != nil {
|
||||
@@ -83,6 +94,12 @@ func main() {
|
||||
log.Fatal().Err(err).Msg("Failed to add totp command")
|
||||
}
|
||||
|
||||
err = cmdTinyauth.AddCommand(cmdOidc)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to add oidc command")
|
||||
}
|
||||
|
||||
err = cli.Execute(cmdTinyauth)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -40,7 +40,7 @@ func verifyUserCmd() *cli.Command {
|
||||
|
||||
return &cli.Command{
|
||||
Name: "verify",
|
||||
Description: "Verify a user is set up correctly.",
|
||||
Description: "Verify a user is set up correctly",
|
||||
Configuration: tCfg,
|
||||
Resources: loaders,
|
||||
Run: func(_ []string) error {
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func versionCmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "version",
|
||||
Description: "Print the version number of Tinyauth.",
|
||||
Description: "Print the version number of Tinyauth",
|
||||
Configuration: nil,
|
||||
Resources: nil,
|
||||
Run: func(_ []string) error {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"net"
|
||||
@@ -105,3 +106,9 @@ func GenerateUUID(str string) string {
|
||||
uuid := uuid.NewSHA1(uuid.NameSpaceURL, []byte(str))
|
||||
return uuid.String()
|
||||
}
|
||||
|
||||
func GenerateString(length int) string {
|
||||
src := make([]byte, length)
|
||||
rand.Read(src)
|
||||
return base64.RawURLEncoding.EncodeToString(src)[:length]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user