// A JSON web token is a set of Base64 encoded strings separated by a period (.) // When decoded, it will either be JSON text or a signature // Here we decode the strings into a single token structure and print the most // useful fields. We do not print the signature. func dumpTokenDetails(w io.Writer, name string, encodedToken string) { jwtToken := lightwave.ParseTokenDetails(encodedToken) fmt.Fprintf(w, "%s:\n", name) fmt.Fprintf(w, "\tSubject: %s\n", jwtToken.Subject) fmt.Fprintf(w, "\tGroups: ") if jwtToken.Groups == nil { fmt.Fprintf(w, "<none>\n") } else { fmt.Fprintf(w, "%s\n", strings.Join(jwtToken.Groups, ", ")) } fmt.Fprintf(w, "\tIssued: %s\n", timestampToString(jwtToken.IssuedAt*1000)) fmt.Fprintf(w, "\tExpires: %s\n", timestampToString(jwtToken.Expires*1000)) fmt.Fprintf(w, "\tToken: %s\n", encodedToken) }
// Parse the given token details. func (api *AuthAPI) parseTokenDetails(token string) (jwtToken *lightwave.JWTToken, err error) { jwtToken = lightwave.ParseTokenDetails(token) return jwtToken, nil }