Skip to content

Update auth middleware interface #341

Description

@dmihalcik-virtru

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

???

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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