Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed Dec 23, 2020
1 parent f7bcedd commit 0fd3384
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ import (
"text/tabwriter"

"github.com/benfdking/jen/pkg/defaultjwt"
"github.com/benfdking/jen/pkg/oidc"
"github.com/benfdking/jen/pkg/rsapem"
"github.com/benfdking/jen/pkg/url"
"github.com/spf13/cobra"
)

var key string
var keyFilePath string
var addDefaults bool
var filePath string
var claims map[string]string
var (
key string
keyFilePath string
addDefaults bool
filePath string
oidcStandardClaims bool
claims map[string]string
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -52,6 +56,13 @@ var rootCmd = &cobra.Command{
log.Fatal(err)
}
}
if oidcStandardClaims {
var err error
token, err = defaultjwt.AddMapClaimsToToken(token, oidc.StandardClaims())
if err != nil {
log.Fatal(err)
}
}
if filePath != "" {
var err error
token, err = defaultjwt.AddJSONFileClaimsToToken(token, filePath)
Expand Down Expand Up @@ -85,6 +96,7 @@ var rootCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(versionCmd)

rootCmd.Flags().BoolVarP(&oidcStandardClaims, "oidc", "o", false, "Flag to insert OIDC standard claims")
rootCmd.Flags().StringToStringVarP(&claims, "claims", "c", map[string]string{}, "Claims for JWT")
rootCmd.Flags().StringVarP(&key, "key", "k", "a", "[abc] jwt key to use")
rootCmd.Flags().BoolVarP(&addDefaults, "defaults", "d", true, "Add default claims")
Expand Down
22 changes: 22 additions & 0 deletions pkg/oidc/standardClaims.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package oidc

// StandardClaims returns a map of standard claims as defined by https://openid.net/specs/openid-connect-core-1_0.html.
func StandardClaims() map[string]string {
return map[string]string{
"sub": "90e5763f-7088-426f-941a-984dda3248c8",
"name": "Dr. Michael Smith",
"given_name": "Michael",
"middle_name:": "",
"family_name": "Smith",
"nickname": "Mike",
"preferred_username": "m.smith",
"email": "[email protected]",
"website": "example.com",
"profile": "example.com/Michael.jpg",
"gender": "male",
"birthdate": "1950-12-12",
"zoneinfo": "America/Los_Angeles",
"locale": "en-US",
"updated_at": "1970-01-01T0:0:0Z",
}
}

0 comments on commit 0fd3384

Please sign in to comment.