Skip to content

Commit ec5536b

Browse files
authored
Update the Client Credentials Example for v4 (#1346)
1 parent a334abb commit ec5536b

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

docs/examples/client_credentials.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ The shortest version of the flow looks like this:
4646
# the secret, loaded from wherever you store it
4747
CLIENT_SECRET = "..."
4848
49-
client = globus_sdk.ConfidentialAppAuthClient(CLIENT_ID, CLIENT_SECRET)
50-
token_response = client.oauth2_client_credentials_tokens()
49+
confidential_client = globus_sdk.ConfidentialAppAuthClient(CLIENT_ID, CLIENT_SECRET)
50+
token_response = confidential_client.oauth2_client_credentials_tokens(
51+
requested_scopes=globus_sdk.TransferClient.scopes.all
52+
)
5153
5254
# the useful values that you want at the end of this
53-
globus_auth_data = token_response.by_resource_server["auth.globus.org"]
54-
globus_transfer_data = token_response.by_resource_server["transfer.api.globus.org"]
55-
globus_auth_token = globus_auth_data["access_token"]
55+
globus_transfer_data = token_response.by_resource_server[
56+
globus_sdk.TransferClient.resource_server
57+
]
5658
globus_transfer_token = globus_transfer_data["access_token"]
5759
5860
@@ -69,9 +71,9 @@ For example, after running the code above,
6971
7072
authorizer = globus_sdk.AccessTokenAuthorizer(globus_transfer_token)
7173
tc = globus_sdk.TransferClient(authorizer=authorizer)
72-
print("Endpoints Belonging to {}@clients.auth.globus.org:".format(CLIENT_ID))
74+
print(f"Endpoints Belonging to {CLIENT_ID}@clients.auth.globus.org:")
7375
for ep in tc.endpoint_search(filter_scope="my-endpoints"):
74-
print("[{}] {}".format(ep["id"], ep["display_name"]))
76+
print(f"[{ep['id']}] {ep['display_name']}")
7577
7678
Note that we're doing a search for "my endpoints", but we refer to the results
7779
as belonging to ``<CLIENT_ID>@clients.auth.globus.org``. The "current user" is
@@ -81,8 +83,7 @@ Handling Token Expiration
8183
~~~~~~~~~~~~~~~~~~~~~~~~~
8284

8385
When you get access tokens, you also get their expiration time in seconds.
84-
You can inspect the ``globus_transfer_data`` and ``globus_auth_data``
85-
structures in the example to see.
86+
You can inspect the ``globus_transfer_data`` structure in the example to see.
8687

8788
Tokens should have a long enough lifetime for any short-running operations
8889
(less than a day).
@@ -104,20 +105,20 @@ Use it like so:
104105
105106
import globus_sdk
106107
107-
# you must have a client ID
108+
# you must have a client ID and secret
108109
CLIENT_ID = "..."
109-
# the secret, loaded from wherever you store it
110110
CLIENT_SECRET = "..."
111111
112112
confidential_client = globus_sdk.ConfidentialAppAuthClient(
113113
client_id=CLIENT_ID, client_secret=CLIENT_SECRET
114114
)
115-
scopes = "urn:globus:auth:scope:transfer.api.globus.org:all"
116-
cc_authorizer = globus_sdk.ClientCredentialsAuthorizer(confidential_client, scopes)
115+
cc_authorizer = globus_sdk.ClientCredentialsAuthorizer(
116+
confidential_client, globus_sdk.TransferClient.scopes.all
117+
)
117118
# create a new client
118119
tc = globus_sdk.TransferClient(authorizer=cc_authorizer)
119120
120121
# usage is still the same
121-
print("Endpoints Belonging to {}@clients.auth.globus.org:".format(CLIENT_ID))
122+
print(f"Endpoints Belonging to {CLIENT_ID}@clients.auth.globus.org:")
122123
for ep in tc.endpoint_search(filter_scope="my-endpoints"):
123-
print("[{}] {}".format(ep["id"], ep["display_name"]))
124+
print(f"[{ep['id']}] {ep['display_name']}")

0 commit comments

Comments
 (0)