Commit 9926a0dc authored by Cosmin Cojocar's avatar Cosmin Cojocar

Extend the API with a function which updates the client configuration

parent 57b10313
This diff is collapsed.
......@@ -36,6 +36,21 @@ message DeleteClientResp {
bool not_found = 1;
}
// UpdateClientReq is a request to update an exisitng client.
message UpdateClientReq {
string id = 1;
repeated string redirect_uris = 2;
repeated string trusted_peers = 3;
bool public = 4;
string name = 5;
string logo_url = 6;
}
// UpdateClientResp returns the reponse form updating a client.
message UpdateClientResp {
bool not_found = 1;
}
// TODO(ericchiang): expand this.
// Password is an email for password mapping managed by the storage.
......@@ -138,6 +153,8 @@ message RevokeRefreshResp {
service Dex {
// CreateClient creates a client.
rpc CreateClient(CreateClientReq) returns (CreateClientResp) {};
// UpdateClient updates an exisitng client
rpc UpdateClient(UpdateClientReq) returns (UpdateClientResp) {};
// DeleteClient deletes the provided client.
rpc DeleteClient(DeleteClientReq) returns (DeleteClientResp) {};
// CreatePassword creates a password.
......
......@@ -80,6 +80,38 @@ func (d dexAPI) CreateClient(ctx context.Context, req *api.CreateClientReq) (*ap
}, nil
}
func (d dexAPI) UpdateClient(ctx context.Context, req *api.UpdateClientReq) (*api.UpdateClientResp, error) {
if req.Id == "" {
return nil, errors.New("update client: no client ID supplied")
}
err := d.s.UpdateClient(req.Id, func(old storage.Client) (storage.Client, error) {
if req.RedirectUris != nil && len(req.RedirectUris) > 0 {
old.RedirectURIs = req.RedirectUris
}
if req.TrustedPeers != nil && len(req.TrustedPeers) > 0 {
old.TrustedPeers = req.TrustedPeers
}
old.Public = req.Public
if req.Name != "" {
old.Name = req.Name
}
if req.LogoUrl != "" {
old.LogoURL = req.LogoUrl
}
return old, nil
})
if err != nil {
if err == storage.ErrNotFound {
return &api.UpdateClientResp{NotFound: true}, nil
}
d.logger.Errorf("api: failed to update the client: %v", err)
return nil, fmt.Errorf("update client: %v", err)
}
return &api.UpdateClientResp{}, nil
}
func (d dexAPI) DeleteClient(ctx context.Context, req *api.DeleteClientReq) (*api.DeleteClientResp, error) {
err := d.s.DeleteClient(req.Id)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment