curved-fountain-46946
01/04/2023, 5:00 PMmagnificent-energy-493
curved-fountain-46946
01/05/2023, 9:56 AMcurved-fountain-46946
01/05/2023, 12:06 PMmagnificent-energy-493
curved-fountain-46946
01/05/2023, 1:26 PMcurved-fountain-46946
01/05/2023, 1:27 PMmagnificent-energy-493
curved-fountain-46946
01/05/2023, 1:54 PMmagnificent-energy-493
curved-fountain-46946
01/05/2023, 2:42 PMcurved-fountain-46946
01/09/2023, 3:08 PMcurved-fountain-46946
01/09/2023, 3:17 PMAPIClient.ProjectApi.GetProject
and APIClient.ProjectApi.PatchProject
magnificent-energy-493
curved-fountain-46946
01/09/2023, 6:42 PMnarrow-van-43826
01/10/2023, 8:14 AMnamespaces.location
key of the config should contain a base64 URL of the namespace configuration you want to write, as base64://<base64-encoded data>
.steep-lamp-91158
api.console.ory.sh
, not your slug host.curved-fountain-46946
01/10/2023, 2:42 PMcurved-fountain-46946
01/11/2023, 12:52 PMmagnificent-energy-493
magnificent-energy-493
curved-fountain-46946
01/11/2023, 1:06 PMcurved-fountain-46946
01/11/2023, 1:06 PMmagnificent-energy-493
curved-fountain-46946
01/11/2023, 1:45 PMc.AddDefaultHeader("Authorization", "Bearer "+sessionToken)
Hacky, I know, but it was easier than having to replace the entire http client πcurved-fountain-46946
01/11/2023, 1:58 PMcurved-fountain-46946
01/11/2023, 5:26 PMcurved-fountain-46946
01/11/2023, 5:29 PMfunc NewOryNamespaceClient(url *url.URL, user, password, projectId string, httpClient http.Client) NamespaceClient {
c := ory.NewConfiguration()
kratosUrl, _ := url.Parse("")
kratosUrl.Host = "project." + kratosUrl.Host
url.Host = "api." + url.Host
c.Servers = ory.ServerConfigurations{{URL: url.String()}}
c.HTTPClient = httpClient.(*gohttp.Client)
c.OperationServers["FrontendApiService.CreateNativeLoginFlow"] = ory.ServerConfigurations{{URL: kratosUrl.String()}}
c.OperationServers["FrontendApiService.UpdateLoginFlow"] = ory.ServerConfigurations{{URL: kratosUrl.String()}}
return &oryClient{
ory.NewAPIClient(c),
"",
&oryNamespacesContext{
user: user,
password: password,
projectId: projectId,
},
}
}
is how I set up the client.
func (oc *oryClient) authenticate(ctx context.Context) error {
flow, _, err := oc.FrontendApi.CreateNativeLoginFlow(ctx).Execute()
if err != nil {
return err
}
login, _, err := oc.FrontendApi.UpdateLoginFlow(ctx).Flow(flow.Id).UpdateLoginFlowBody(ory.UpdateLoginFlowBody{
UpdateLoginFlowWithPasswordMethod: ory.NewUpdateLoginFlowWithPasswordMethod(oc.nsContext.user, "password", oc.nsContext.password),
}).Execute()
if err != nil {
return err
}
oc.token = *login.SessionToken
return nil
}
is how I authenticate, and
func (oc *oryClient) UpdateNamespaces(ctx context.Context, namespaces map[string]int) (*ory.SuccessfulProjectUpdate, error) {
out := make([]Namespace, len(namespaces))
var i int
for name, id := range namespaces {
out[i] = Namespace{
Id: id,
Name: name,
}
i++
}
patch := []ory.JsonPatch{
{
Op: OryOpReplace,
Path: "/services/permission/config/" + OryNamespacesKey,
// We may have to encode something here, to like json or yaml, who knows?
Value: out,
},
}
success, res, err := oc.patchProject(ctx, patch)
if res.StatusCode == gohttp.StatusUnauthorized {
if err := oc.authenticate(ctx); err != nil {
return nil, err
}
success, _, err = oc.patchProject(ctx, patch)
}
return success, err
}
Is how I update namespaces. The logic of appending new namespaces to the existing list is handled outside of my ory client wrapper π.magnificent-energy-493