cmd

package
v0.0.0-...-2d60ba9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AlgorithmsCmd = &cobra.Command{
	Use:   "algorithms",
	Short: "list available algorithms",
	Long:  "lists all the available algorithms you can use for signing the JWT",
	Run: func(cmd *cobra.Command, args []string) {
		for _, a := range model.Algorithms {
			fmt.Println(a)
		}
	},
}

AlgorithmsCmd lists the supported algorithms

View Source
var CreateCmd = &cobra.Command{
	Use:   "create [flags]",
	Short: "create a JWT",
	Long:  "creates a JWT using the specified flags and key/value pairs",
	Run: func(cmd *cobra.Command, args []string) {

		algorithm, ok := model.AlgorithmForName(algo)
		if !ok {
			fmt.Printf("algorithm '%s' not valid\n", algo)
			os.Exit(1)
		}

		claims := &jwt.StandardClaims{
			Subject: sub,
		}

		var signedString string
		var err error
		token := jwt.NewWithClaims(algorithm, claims)

		if algorithm == jwt.SigningMethodNone {
			signedString, err = token.SignedString(jwt.UnsafeAllowNoneSignatureType)
		} else {
			signedString, err = token.SignedString([]byte(key))
		}
		if err != nil {
			fmt.Println(err.Error())
			os.Exit(1)
		}
		fmt.Println(signedString)
	},
}

CreateCmd lists the supported algorithms

View Source
var RootCmd = &cobra.Command{
	Use:   "jwtbot",
	Short: "A CLI for creating JWTs",
	Long:  "jwtbot lets you create JWTs",
}

RootCmd is the root command for jwtbot

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flag appropriately

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL