22
33Campus Auth Clients resource (v1).
44"""
5+ from __future__ import annotations
56
6- from campus .common import env
77import campus .model
88
99from ...interface import JsonDict , Resource , ResourceCollection
@@ -26,11 +26,31 @@ def list(self) -> "list[campus.model.Client]":
2626 for item in resp .json ()["clients" ]
2727 ]
2828
29- def new (self , name : str , description : str ) -> campus .model .Client :
30- resp = self .client .post (self .make_path (), json = {
29+ def new (
30+ self ,
31+ name : str ,
32+ description : str ,
33+ is_public : bool = False ,
34+ redirect_uris : list [str ] | None = None
35+ ) -> campus .model .Client :
36+ """Create a new client.
37+
38+ Args:
39+ name: Client name
40+ description: Client description
41+ is_public: True for public clients (CLI/mobile apps) without secrets
42+ redirect_uris: OAuth redirect URIs for public clients
43+
44+ Returns:
45+ The created Client
46+ """
47+ json_data = {
3148 "name" : name ,
3249 "description" : description ,
33- })
50+ "is_public" : is_public ,
51+ "redirect_uris" : redirect_uris or []
52+ }
53+ resp = self .client .post (self .make_path (), json = json_data )
3454 # Raise error if status code is not 2XX or 3XX
3555 resp .raise_for_status ()
3656 return campus .model .Client .from_resource (resp .json ())
@@ -71,12 +91,29 @@ def revoke(self) -> str:
7191 resp .raise_for_status ()
7292 return resp .json ()["secret" ]
7393
74- def update (self , name : str | None = None , description : str | None = None ) -> campus .model .Client :
94+ def update (
95+ self ,
96+ name : str | None = None ,
97+ description : str | None = None ,
98+ redirect_uris : list [str ] | None = None
99+ ) -> campus .model .Client :
100+ """Update the client.
101+
102+ Args:
103+ name: New client name
104+ description: New client description
105+ redirect_uris: New OAuth redirect URIs
106+
107+ Returns:
108+ The updated Client
109+ """
75110 json_data = {}
76111 if name is not None :
77112 json_data ["name" ] = name
78113 if description is not None :
79114 json_data ["description" ] = description
115+ if redirect_uris is not None :
116+ json_data ["redirect_uris" ] = redirect_uris
80117 resp = self .client .put (self .make_path (), json = json_data )
81118 # Raise error if status code is not 2XX or 3XX
82119 resp .raise_for_status ()
0 commit comments