@@ -12,7 +12,70 @@ TODO INSTALL setup a KBase pypi org and publish there
1212
1313## Usage
1414
15- TODO USAGE
15+ Both sync and async versions of the client are provided - ` KBaseAuthClient `
16+ and ` AsyncKBaseAuthClient ` , respectively. Here we demonstrate usage of the async client -
17+ to use the sync client, just switch the client name when creating the client and remove the
18+ ` async ` and ` await ` keywords. The examples assume there is a valid KBase token in the
19+ ` token ` variable.
20+
21+ Note that all methods have internal caches and further caching is not necessary.
22+
23+ Replace the CI environment url with the url of the environment you wish to query.
24+
25+ ### Get the version of the auth service
26+
27+ ``` python
28+ from kbase.auth import AsyncKBaseAuthClient
29+
30+ async with await AsyncKBaseAuthClient.create(" https://ci.kbase.us/services/auth" ) as cli:
31+ print (await cli.service_version())
32+ 0.7 .2
33+ ```
34+
35+ ### Get a token
36+
37+ This is the cheapest method to get a KBase username from a token.
38+
39+ ``` python
40+ from kbase.auth import AsyncKBaseAuthClient
41+
42+ async with await AsyncKBaseAuthClient.create(" https://ci.kbase.us/services/auth" ) as cli:
43+ print (await cli.get_token(token))
44+ Token(id = ' 67797406-c6a3-4ee0-870d-976739dacd61' , user = ' gaprice' , created = 1755561300704 , expires = 1763337300704 , cachefor = 300000 )
45+ ```
46+
47+ ### Get a user
48+
49+ ``` python
50+ from kbase.auth import AsyncKBaseAuthClient
51+
52+ async with await AsyncKBaseAuthClient.create(" https://ci.kbase.us/services/auth" ) as cli:
53+ print (await cli.get_user(token))
54+ User(user = ' gaprice' , customroles = [' KBASE_STAFF' , ' goofypants' ])
55+ ```
56+
57+ ### Validate usernames
58+
59+ ``` python
60+ from kbase.auth import AsyncKBaseAuthClient
61+
62+ async with await AsyncKBaseAuthClient.create(" https://ci.kbase.us/services/auth" ) as cli:
63+ print (await cli.validate_usernames(token, " gaprice" , " superfake" ))
64+ {' gaprice' : True , ' superfake' : False }
65+ ```
66+
67+ ### Without a context manager
68+
69+ The clients can be used without a context manager, in which case the user is responsible for
70+ ensuring they're closed:
71+
72+ ``` python
73+ from kbase.auth import AsyncKBaseAuthClient
74+
75+ cli = await AsyncKBaseAuthClient.create(" https://ci.kbase.us/services/auth" )
76+
77+ await cli.close()
78+ ```
1679
1780## Development
1881
@@ -40,6 +103,7 @@ uv run scripts/process_unasync.py
40103* Releases
41104 * The main branch is the stable branch. Releases are made from the develop branch to the main
42105 branch.
106+ * Update the version in ` auth.py ` .
43107 * Tag the version in git and github.
44108 * Create a github release.
45109
0 commit comments