Ok - so what may have happened is some of the acco...
# ory-selfhosting
p
Ok - so what may have happened is some of the accounts were created before recovery was turned on. So my new question is how can I extract email addresses from identity traits and set that email as a recovery email for accounts that do not have it set? I want to be able to "turn on" account recovery for accounts created before recovery was active.
Is this still expected to work? I cannot seem to curl to that endpoint and update an existing identity. I give credentials, but still get 409 Conflict in return.
If anyone needs it, here is a small example program to add a recovery address to an identity in kratos
Copy code
package 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)                                                                   
}
And a program that will add the recovery addresses to all identities which do not have it set. I think that Kratos should do this a automatically when the service is restarted and the configuration now has recovery enabled.