Skip to content

Proposal: add StreamableClientTransport.OAuthHandler #591

@jba

Description

@jba

We should add this field to StreamableClientTransport:

OAuthHandler auth.OAuthHandler

The type is defined here.

I believe that gives us everything we need for auth. It does couple the streamable transport to OAuth, but so does the spec, and the TypeScript SDK.

Our SDK will call the handler when a request returns a 403. If the handler returns a TokenSource, the SDK will use it to set the Authorization header on subsequent calls.

If the handler can't return a TokenSource because user approval must occur out of band, it should return an error, which will be passed up to the caller. The caller can then do whatever it needs to obtain a token, and then begin again with with a new transport whose handler simply returns the token. Or one handler can suffice for both cases: it first looks for a token somewhere (a shared variable), and if it finds it, returns it. Otherwise, it conducts the OAuth flow and returns the resulting token.

Previously, we tried to do this entirely within an http.Client. That approach is cleaner, but is a bit messy to implement, and more important, has an unfixable bug (until golang/go#75814 is available) in which a RoundTripper inserts an Authorization header incorrectly.

We also proposed adding a ModifyRequest option. That is more general, and maybe we should still add it to support adding other headers and modifying the request in other ways. But for setting the Authorization header, I think this proposal suffices. If you have an access token, you can get the effect of ModifyRequest easily enough: wrap it in a TokenSource by creating a Token and passing it to a StaticTokenSource, and then your handler can just return that TokenSource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions