Feat:Added Update Client
This commit is contained in:
@@ -95,6 +95,53 @@ def create_org_client(org_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_v1_bp.route("/organizations/<org_id>/clients/<client_id>", methods=["PATCH"])
|
||||||
|
@login_required
|
||||||
|
@require_admin
|
||||||
|
def update_org_client(org_id, client_id):
|
||||||
|
from gatehouse_app.models import OIDCClient
|
||||||
|
|
||||||
|
client = OIDCClient.query.filter_by(id=client_id, organization_id=org_id).first()
|
||||||
|
if not client:
|
||||||
|
return api_response(success=False, message="Client not found", status=404)
|
||||||
|
|
||||||
|
data = request.get_json() or {}
|
||||||
|
|
||||||
|
if "name" in data:
|
||||||
|
name = (data["name"] or "").strip()
|
||||||
|
if not name:
|
||||||
|
return api_response(success=False, message="Client name cannot be empty", status=400, error_type="VALIDATION_ERROR")
|
||||||
|
client.name = name
|
||||||
|
|
||||||
|
if "redirect_uris" in data:
|
||||||
|
redirect_uris_raw = data["redirect_uris"]
|
||||||
|
if isinstance(redirect_uris_raw, str):
|
||||||
|
uris = [u.strip() for u in redirect_uris_raw.replace(",", "\n").splitlines() if u.strip()]
|
||||||
|
else:
|
||||||
|
uris = [u.strip() for u in redirect_uris_raw if isinstance(u, str) and u.strip()]
|
||||||
|
if not uris:
|
||||||
|
return api_response(success=False, message="At least one redirect URI is required", status=400, error_type="VALIDATION_ERROR")
|
||||||
|
client.redirect_uris = uris
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return api_response(
|
||||||
|
data={
|
||||||
|
"client": {
|
||||||
|
"id": client.id,
|
||||||
|
"name": client.name,
|
||||||
|
"client_id": client.client_id,
|
||||||
|
"redirect_uris": client.redirect_uris,
|
||||||
|
"scopes": client.scopes,
|
||||||
|
"grant_types": client.grant_types,
|
||||||
|
"is_active": client.is_active,
|
||||||
|
"created_at": client.created_at.isoformat() + "Z",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
message="Client updated successfully",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@api_v1_bp.route("/organizations/<org_id>/clients/<client_id>", methods=["DELETE"])
|
@api_v1_bp.route("/organizations/<org_id>/clients/<client_id>", methods=["DELETE"])
|
||||||
@login_required
|
@login_required
|
||||||
@require_admin
|
@require_admin
|
||||||
|
|||||||
Reference in New Issue
Block a user