OAuth¶
octomate.oauth.base ¶
What every provider's OAuth shares, below the flows themselves.
A credential is worth little at rest: it has to be carried to an upstream, and the upstream is the only thing that can say it has stopped working. That round trip belongs to no single provider, so it lives here rather than in one of them.
McpBearerAuth ¶
Bases: Auth
Source code in octomate/oauth/base.py
headers ¶
Return the upstream's authentication headers for the user's token.
async_auth_flow
async
¶
Source code in octomate/oauth/base.py
octomate.oauth.flows ¶
Standard OAuth flows shared by channels and MCP integrations.
OAuthRefreshRejected ¶
DeviceCodeResponse
pydantic-model
¶
Bases: BaseModel
Fields:
-
device_code(SecretStr) -
user_code(SecretStr) -
verification_uri(HttpsUrl) -
verification_uri_complete(HttpsUrl | None) -
expires_in(int) -
interval(int)
Source code in octomate/oauth/flows.py
TokenError
pydantic-model
¶
Bases: BaseModel
Fields:
-
error(str) -
error_description(str | None) -
interval(int | None)
Source code in octomate/oauth/flows.py
OAuthTokenExchange ¶
Source code in octomate/oauth/flows.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
response_adapter
instance-attribute
¶
response_adapter: TypeAdapter[OAuthToken | TokenError] = (
TypeAdapter(
Annotated[
Annotated[self.token_model, Tag("token")]
| Annotated[TokenError, Tag("error")],
Discriminator(token_response_kind),
]
)
)
authorization_endpoint
instance-attribute
¶
invalid_credentials_errors
instance-attribute
¶
invalid_credentials_errors: list[str] = (
invalid_credentials_errors
if invalid_credentials_errors is not None
else ["invalid_grant", "invalid_client"]
)
httpx_client_factory
instance-attribute
¶
discovery_state
instance-attribute
¶
send
async
staticmethod
¶
Source code in octomate/oauth/flows.py
request
async
¶
Source code in octomate/oauth/flows.py
parse_response ¶
grant
async
¶
Source code in octomate/oauth/flows.py
refresh
async
¶
Source code in octomate/oauth/flows.py
OAuthTokenResolver ¶
Bases: Protocol
Source code in octomate/oauth/flows.py
AuthorizationCodeFlow ¶
Authorization-code OAuth using a configured or discovered client.
Source code in octomate/oauth/flows.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
authorization_lifetime
instance-attribute
¶
resolve_tokens
async
¶
start
async
¶
start(
context: OAuthFlowContext,
callback_uri: AnyHttpUrl,
state: SecretStr,
) -> AuthorizationRequest
Source code in octomate/oauth/flows.py
exchange
async
¶
exchange(
context: OAuthFlowContext,
*,
code: str,
code_verifier: SecretStr | None,
callback_uri: AnyHttpUrl,
) -> OAuthGrant
Source code in octomate/oauth/flows.py
DeviceAuthorizationFlow ¶
OAuth device authorization with polling and token refresh.
Source code in octomate/oauth/flows.py
device_authorization_endpoint
instance-attribute
¶
start
async
¶
Source code in octomate/oauth/flows.py
complete
async
¶
Source code in octomate/oauth/flows.py
token_response_kind ¶
Source code in octomate/oauth/flows.py
octomate.oauth.mcp ¶
MCP resource discovery and dynamic OAuth client registration.
McpOAuthDiscovery ¶
Source code in octomate/oauth/mcp.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
httpx_client_factory
instance-attribute
¶
discovery_state
instance-attribute
¶
resolve
async
¶
Source code in octomate/oauth/mcp.py
discover
async
¶
Source code in octomate/oauth/mcp.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
octomate.oauth.routes ¶
The browser half of an authorization-code connection.
Two routes, and deliberately only two: one that turns a UUID into the provider's real authorization request, and one the provider sends the user back to. Both are opened by a person's browser rather than called by anything — the authorization server never connects here, it only redirects the user agent — so what they answer with is a page for someone to read, and what they refuse with is the same page for every way of refusing.
Neither route authenticates its caller, because there is nobody to authenticate: the
callback arrives out of band with no channel identity attached. Everything binding
the round trip to one person was settled when the authorization started and is
rechecked in OAuthManager.complete_callback.
page ¶
The whole user-facing surface of this router.
Says what happened and where the rest of the errand is, and nothing else — no provider name in an error, no operation id, no reason. Someone who reaches a refusal here is either the user, who needs to go back and ask again, or someone who should learn nothing from having tried.
Source code in octomate/oauth/routes.py
start
async
¶
start(
connector_id: str,
operation_id: UUID7,
manager: Annotated[
OAuthManager, Depends(oauth_manager)
],
) -> Response
Source code in octomate/oauth/routes.py
callback
async
¶
callback(
connector_id: str,
manager: Annotated[
OAuthManager, Depends(oauth_manager)
],
state: Annotated[str, Query()] = "",
code: Annotated[str, Query()] = "",
error: Annotated[str, Query()] = "",
iss: Annotated[str | None, Query()] = None,
) -> HTMLResponse | RedirectResponse
Source code in octomate/oauth/routes.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
Lark / Feishu¶
octomate.tentacles.lark.oauth ¶
Feishu MCP authentication and user identity verification.
LarkMcpBearerAuth ¶
Bases: McpBearerAuth
The special case Feishu makes ordinary bearer authentication need.
Feishu's developer-app MCP endpoint carries the user token in
X-Lark-MCP-UAT instead of Authorization: Bearer .... Renaming the header
adds no protection against a caller holding the token. It does force an
otherwise generic OAuth client to grow a provider-specific adapter.
X-Lark-MCP-Allowed-Tools carries the comma-separated mcp_tools list.
Feishu's contract
uses it to filter discovery and calls; omitting it exposes no tools.
That makes it useful for selecting tools. Calling the header "Allowed"
does not turn a caller's wish list into authorization: a client or agent
holding the token and controlling HTTP requests can submit a wider list
with the same credential, including on a new connection. This design adds
integration work without establishing a separate permission boundary.
Octomate sets these headers from deployment configuration; proxied tool arguments cannot override them. The limitation concerns clients that hold the credential themselves. Keep grants narrow using OAuth scopes and the provider's app and resource permissions. Changing this header grants none of those permissions and does not restrict the token outside this client.
Source code in octomate/tentacles/lark/oauth.py
headers ¶
Source code in octomate/tentacles/lark/oauth.py
LarkOAuthIdentity
pydantic-model
¶
Bases: BaseModel
The app-scoped user identified by Feishu's user_info endpoint.
Fields:
Source code in octomate/tentacles/lark/oauth.py
LarkUserInfoResponse
pydantic-model
¶
Bases: BaseModel
A successful user_info response; provider errors fail validation.
Fields:
-
code(Literal[0]) -
data(LarkOAuthIdentity)
Source code in octomate/tentacles/lark/oauth.py
LarkOAuthConnector
pydantic-model
¶
Bases: OAuthConnector
Link the user proven by the app's token, using its app-scoped open ID.
Feishu's API versions are a compatibility trap. Its
token migration advice
recommends v3, while the code_challenge parameter in
Get authorization code
explicitly recommends pairing PKCE with the v2 token endpoint and says
support for the latest token endpoint will follow. Those recommendations
contradict each other; choosing the highest version breaks this flow.
Octomate uses v1 authorization with S256 PKCE, v2 token exchange and refresh, and v1 user-info lookup. These version numbers do not describe one shared protocol version. In this integration, v3 rejected the authorization code despite the saved verifier matching the authorization challenge; switching to v2 completed a fresh authorization successfully. Keep PKCE enabled and retain the documented v1/v2 pairing until Feishu supports and verifies its replacement.
App credentials are sent in the token request's form body. The MCP headers
X-Lark-MCP-UAT and X-Lark-MCP-Allowed-Tools are independent of these OAuth
endpoint versions.
Fields:
-
id(str) -
flows(list[DeviceAuthorizationFlow | AuthorizationCodeFlow]) -
callback_transport(OAuthCallbackTransport | None) -
mcp_url(HttpsUrl | None) -
httpx_client_factory(Callable[[], AsyncClient])
Validators: