plain-lunch-50969
04/17/2024, 5:13 PMplain-lunch-50969
04/17/2024, 5:24 PMplain-lunch-50969
04/17/2024, 6:11 PMplain-lunch-50969
04/17/2024, 8:31 PMpackage main
import (
"context"
"fmt"
"net/http"
"os"
"encoding/json"
ory "github.com/ory/client-go"
"github.com/ory/kratos/x"
)
var (
KratosAdminURL string = "<http://kratos-admin>"
)
func KratosAdminCli() *ory.APIClient {
conf := ory.NewConfiguration()
conf.Servers = []ory.ServerConfiguration{{
URL: KratosAdminURL,
}}
return ory.NewAPIClient(conf)
}
func PrintJSONPretty(v interface{}) {
out, _ := json.MarshalIndent(v, "", " ")
fmt.Println(string(out))
}
func SDKExitOnError(err error, res *http.Response) {
if err == nil {
return
}
var body []byte
if res != nil {
body, _ = json.MarshalIndent(json.RawMessage(x.MustReadAll(res.Body)), "", " ")
}
out, _ := json.MarshalIndent(err, "", " ")
fmt.Printf("%s\n\nAn error occurred: %+v\nbody: %s\n", out, err, body)
os.Exit(1)
}
func main() {
ctx := context.Background()
userid := "fcd5fdb8-4626-4841-92f2-d6292b01729c"
useremail := "user519@example.net"
cli := KratosAdminCli()
patch := []ory.JsonPatch{{
Op: "replace",
Path: "/recovery_addresses",
Value: []ory.RecoveryIdentityAddress{{
Id: userid,
Value: useremail,
Via: "email",
}},
}}
id, resp, err := cli.IdentityApi.PatchIdentity(ctx, userid).JsonPatch(patch).Execute()
SDKExitOnError(err, resp)
PrintJSONPretty(id)
}
plain-lunch-50969
04/17/2024, 9:08 PM