Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions docs/tools/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,41 @@ Pass the scheme and credential during toolset initialization. The toolset applie
)
```

=== "Client Credentials Grant Type"

For machine-to-machine authentication, you can use the OAuth2 Client Credentials grant type. This flow is non-interactive and uses the client ID and client secret to obtain an access token.

```python
from fastapi.openapi.models import OAuth2, OAuthFlowClientCredentials, OAuthFlows
from google.adk.auth import AuthCredential, AuthCredentialTypes, OAuth2Auth
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import OpenAPIToolset

# Define OAuth2 scheme with client credentials flow
flows = OAuthFlows(
clientCredentials={
"tokenUrl": "https://example.com/token",
"scopes": {"read:weather": "Read weather data"},
}
)
auth_scheme = OAuth2(flows=flows)

# Define AuthCredential with client ID and client secret
auth_credential = AuthCredential(
auth_type=AuthCredentialTypes.OAUTH2,
oauth2=OAuth2Auth(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
),
)

weather_toolset = OpenAPIToolset(
spec_str="...", # Your OpenAPI spec
spec_str_type="yaml",
auth_scheme=auth_scheme,
auth_credential=auth_credential,
)
```

=== "Service Account"

Create a tool requiring Service Account.
Expand Down Expand Up @@ -568,7 +603,7 @@ except Exception as e:
email: [email protected] # Replace with actual contact if available
servers:
- url: <substitute with your server name>
description: Production Environment
description: Production Environment
paths:
/okta-jwt-user-api:
get:
Expand Down Expand Up @@ -676,4 +711,3 @@ except Exception as e:
- code
- message
```