MCPcopy
hub / github.com/golang-jwt/jwt / showToken

Function showToken

cmd/jwt/main.go:266–296  ·  view source on GitHub ↗

showToken pretty-prints the token on the command line.

()

Source from the content-addressed store, hash-verified

264
265// showToken pretty-prints the token on the command line.
266func showToken() error {
267 // get the token
268 tokData, err := loadData(*flagShow)
269 if err != nil {
270 return fmt.Errorf("couldn't read token: %w", err)
271 }
272
273 // trim possible whitespace from token
274 tokData = regexp.MustCompile(`\s*$`).ReplaceAll(tokData, []byte{})
275 if *flagDebug {
276 fmt.Fprintf(os.Stderr, "Token len: %v bytes\n", len(tokData))
277 }
278
279 token, _, err := jwt.NewParser().ParseUnverified(string(tokData), make(jwt.MapClaims))
280 if err != nil {
281 return fmt.Errorf("malformed token: %w", err)
282 }
283
284 // Print the token details
285 fmt.Println("Header:")
286 if err := printJSON(token.Header); err != nil {
287 return fmt.Errorf("failed to output header: %w", err)
288 }
289
290 fmt.Println("Claims:")
291 if err := printJSON(token.Claims); err != nil {
292 return fmt.Errorf("failed to output claims: %w", err)
293 }
294
295 return nil
296}
297
298func isEs() bool {
299 return strings.HasPrefix(*flagAlg, "ES")

Callers 1

startFunction · 0.85

Calls 3

loadDataFunction · 0.85
printJSONFunction · 0.85
ParseUnverifiedMethod · 0.80

Tested by

no test coverage detected