func getAccessToken() string {
issuer := zitadelDomain
jsonFilePath := "api.json" // Ensure this constant/variable is defined
scopes := []string{oidc.ScopeOpenID, "urn:zitadel:iam:org:project🆔zitadel:aud"} // Adjust scopes as needed, but you need it to access zitadel APIs
tokenSource, err := profile.NewJWTProfileTokenSourceFromKeyFile(issuer, jsonFilePath, scopes)
if err != nil {
// Log the values being used
log.Printf("❌ Failed to create JWT profile token source. Issuer: '%s', Keyfile: '%s'. Error: %v", issuer, jsonFilePath, err)
log.Fatalf("Exiting.") // Use Fatalf to print and exit
}
// Retrieve the token using the token source
token, err := tokenSource.Token()
if err != nil {
log.Fatalf("❌ Failed to get access token using JWT profile: %v", err)
}
fmt.Println("✅ Access Token Obtained via JWT Profile Grant")
return token.AccessToken
}
func getAccessToken() string {
issuer := zitadelDomain
jsonFilePath := "api.json" // Ensure this constant/variable is defined
scopes := []string{oidc.ScopeOpenID, "urn:zitadel:iam:org:project🆔zitadel:aud"} // Adjust scopes as needed, but you need it to access zitadel APIs
tokenSource, err := profile.NewJWTProfileTokenSourceFromKeyFile(issuer, jsonFilePath, scopes)
if err != nil {
// Log the values being used
log.Printf("❌ Failed to create JWT profile token source. Issuer: '%s', Keyfile: '%s'. Error: %v", issuer, jsonFilePath, err)
log.Fatalf("Exiting.") // Use Fatalf to print and exit
}
// Retrieve the token using the token source
token, err := tokenSource.Token()
if err != nil {
log.Fatalf("❌ Failed to get access token using JWT profile: %v", err)
}
fmt.Println("✅ Access Token Obtained via JWT Profile Grant")
return token.AccessToken
}