The auth config sent by tool asking client to collect auth credentials and adk and client will help to fill in the response
| 49 | |
| 50 | |
| 51 | class AuthConfig(BaseModelWithConfig): |
| 52 | """The auth config sent by tool asking client to collect auth credentials and |
| 53 | |
| 54 | adk and client will help to fill in the response |
| 55 | """ |
| 56 | |
| 57 | auth_scheme: AuthScheme |
| 58 | """The auth scheme used to collect credentials""" |
| 59 | raw_auth_credential: Optional[AuthCredential] = None |
| 60 | """The raw auth credential used to collect credentials. The raw auth |
| 61 | credentials are used in some auth scheme that needs to exchange auth |
| 62 | credentials. e.g. OAuth2 and OIDC. For other auth scheme, it could be None. |
| 63 | """ |
| 64 | exchanged_auth_credential: Optional[AuthCredential] = None |
| 65 | """The exchanged auth credential used to collect credentials. adk and client |
| 66 | will work together to fill it. For those auth scheme that doesn't need to |
| 67 | exchange auth credentials, e.g. API key, service account etc. It's filled by |
| 68 | client directly. For those auth scheme that need to exchange auth credentials, |
| 69 | e.g. OAuth2 and OIDC, it's first filled by adk. If the raw credentials |
| 70 | passed by tool only has client id and client credential, adk will help to |
| 71 | generate the corresponding authorization uri and state and store the processed |
| 72 | credential in this field. If the raw credentials passed by tool already has |
| 73 | authorization uri, state, etc. then it's copied to this field. Client will use |
| 74 | this field to guide the user through the OAuth2 flow and fill auth response in |
| 75 | this field""" |
| 76 | |
| 77 | credential_key: Optional[str] = None |
| 78 | """A user specified key used to load and save this credential in a credential |
| 79 | service. |
| 80 | """ |
| 81 | |
| 82 | def __init__(self, **data): |
| 83 | super().__init__(**data) |
| 84 | if self.credential_key: |
| 85 | return |
| 86 | for obj in (self.raw_auth_credential, self.auth_scheme): |
| 87 | if not obj or not getattr(obj, "model_extra", None): |
| 88 | continue |
| 89 | for key in ("credential_key", "credentialKey"): |
| 90 | value = obj.model_extra.get(key) |
| 91 | if isinstance(value, str) and value: |
| 92 | self.credential_key = value |
| 93 | return |
| 94 | self.credential_key = self.get_credential_key() |
| 95 | |
| 96 | @deprecated("This method is deprecated. Use credential_key instead.") |
| 97 | def get_credential_key(self): |
| 98 | """Builds a stable key based on auth_scheme and raw_auth_credential. |
| 99 | |
| 100 | This is used to save/load credentials to/from a credential service when |
| 101 | `credential_key` is not explicitly provided. |
| 102 | """ |
| 103 | |
| 104 | auth_scheme = self.auth_scheme |
| 105 | |
| 106 | if auth_scheme.model_extra: |
| 107 | auth_scheme = auth_scheme.model_copy(deep=True) |
| 108 | auth_scheme.model_extra.clear() |
no outgoing calls