Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update auth middleware interface #341

Open
dmihalcik-virtru opened this issue Aug 30, 2024 · 0 comments
Open

Update auth middleware interface #341

dmihalcik-virtru opened this issue Aug 30, 2024 · 0 comments

Comments

@dmihalcik-virtru
Copy link
Member

dmihalcik-virtru commented Aug 30, 2024

The current auth middleware API is

export type AuthProvider = {
  updateClientPublicKey(signingKey?: CryptoKeyPair): Promise<void>;
  withCreds(httpReq: HttpRequest): Promise<HttpRequest>;
};

However, this doesn't have a good way to perform refreshes, or generate an updated DPoP when receiving a DPoP nonce. The middleware needs to have a method that takes an error.

One reason we held off on this is because we want to support both axios and fetch interfaces.

Nice to haves:

  • chainable: we can do dpop updates with nonce and refresh token updates as separate objects
  • simple to call
  • works with both fetch and axios?

Some options:

Aspect oriented:

export type AuthMiddleware = {
  onRequest(req: HttpRequest): Promise<HttpRequest>;
  onResponse(req: HttpRequest, resp: HttpResponse): Promise<HttpRequest>;
};

With sub-object:

export type AuthMiddleware = {
  withHandler(resource: string; options: FetchOptions): MiddlewareHandler;
};

export type MiddlewareHandler = {
  handle(resp: Promise<Response>): Promise<Response>;
};

Interceptors:

export type FetchInterceptor = {
  bind(f: typeof window.fetch): typeof window.fetch;
};

????


Code Samples: Interceptors

???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant