| 1 |
// Package gen allows generating of example tokens and claims. |
| 2 |
// |
| 3 |
// go run ./internal/testutil/gen |
| 4 |
package main |
| 5 |
|
| 6 |
import ( |
| 7 |
"encoding/json" |
| 8 |
"fmt" |
| 9 |
"os" |
| 10 |
|
| 11 |
tu "github.com/zitadel/oidc/v3/internal/testutil" |
| 12 |
"github.com/zitadel/oidc/v3/pkg/oidc" |
| 13 |
) |
| 14 |
|
| 15 |
var custom = map[string]any{ |
| 16 |
"foo": "Hello, World!", |
| 17 |
"bar": struct { |
| 18 |
Count int `json:"count,omitempty"` |
| 19 |
Tags []string `json:"tags,omitempty"` |
| 20 |
}{ |
| 21 |
Count: 22, |
| 22 |
Tags: []string{"some", "tags"}, |
| 23 |
}, |
| 24 |
} |
| 25 |
|
| 26 |
func main() { |
| 27 |
enc := json.NewEncoder(os.Stdout) |
| 28 |
enc.SetIndent("", " ") |
| 29 |
|
| 30 |
accessToken, atClaims := tu.NewAccessTokenCustom( |
| 31 |
tu.ValidIssuer, tu.ValidSubject, tu.ValidAudience, |
| 32 |
tu.ValidExpiration.AddDate(99, 0, 0), tu.ValidJWTID, |
| 33 |
tu.ValidClientID, tu.ValidSkew, custom, |
| 34 |
) |
| 35 |
atHash, err := oidc.ClaimHash(accessToken, tu.SignatureAlgorithm) |
| 36 |
if err != nil { |
| 37 |
panic(err) |
| 38 |
} |
| 39 |
|
| 40 |
idToken, idClaims := tu.NewIDTokenCustom( |
| 41 |
tu.ValidIssuer, tu.ValidSubject, tu.ValidAudience, |
| 42 |
tu.ValidExpiration.AddDate(99, 0, 0), tu.ValidAuthTime, |
| 43 |
tu.ValidNonce, tu.ValidACR, tu.ValidAMR, tu.ValidClientID, |
| 44 |
tu.ValidSkew, atHash, custom, |
| 45 |
) |
| 46 |
|
| 47 |
fmt.Println("access token claims:") |
| 48 |
if err := enc.Encode(atClaims); err != nil { |
| 49 |
panic(err) |
| 50 |
} |
| 51 |
fmt.Printf("access token:\n%s\n", accessToken) |
| 52 |
|
| 53 |
fmt.Println("ID token claims:") |
| 54 |
if err := enc.Encode(idClaims); err != nil { |
| 55 |
panic(err) |
| 56 |
} |
| 57 |
fmt.Printf("ID token:\n%s\n", idToken) |
| 58 |
} |