2.0.13 • Published 7 months ago

@flexbase/http-client-middleware v2.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Coverage Quality Gate Status

http-client-middleware

This is a middleware package to wrap http authentication.

Usage

Using wretch

Client Credentials

const clientCredentials = {
  tokenUrl: "https://some.url/auth/token",
  refreshTokenUrl: "https://some.url/auth/refresh",
  clientId: "myclient id",
  clientSecret: "super secret"
};

class SimpleAuthenticationTokenStore implements AuthenticationTokenStore {
    private _authenticationToken: AuthenticationToken | null = null;

    retrieveToken(): IAuthenticationToken | null {
        return this._authenticationToken;
    }

    storeToken(token: IAuthenticationToken | null): void {
        this._authenticationToken = token;
    }
}

const authMiddleware = authenticationTokenMiddleware({
    credentialProvider: () => clientCredentials,
    tokenAccessor: new ClientCredentialsAuthenticationTokenAccessor(),
    tokenStore: new SimpleAuthenticationTokenStore()
});

wretch(...).middlewares([authMiddleware]);

Password Credentials

// for password creds we only need to supply the urls as user/pass will come from a login form
const passwordCredentials = {
  tokenUrl: "https://some.url/auth/token",
  refreshTokenUrl: "https://some.url/auth/refresh",
};

class SimpleAuthenticationTokenStore implements AuthenticationTokenStore {
    private _authenticationToken: AuthenticationToken | null = null;

    retrieveToken(): IAuthenticationToken | null {
        return this._authenticationToken;
    }

    storeToken(token: IAuthenticationToken | null): void {
        this._authenticationToken = token;
    }
}

const authMiddleware = authenticationTokenMiddleware({
    credentialProvider: () => passwordCredentials,
    tokenAccessor: new PasswordAuthenticationTokenAccessor(),
    tokenStore: new SimpleAuthenticationTokenStore()
});

wretch(...).middlewares([authMiddleware]);
2.0.3

7 months ago

2.0.2

7 months ago

2.0.13

7 months ago

2.0.12

7 months ago

2.0.3-beta.12

7 months ago

1.10.0-beta.1

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.55

2 years ago

1.9.2

2 years ago

1.9.1-beta.25

2 years ago

1.9.1-beta.24

2 years ago

0.0.0

2 years ago

1.9.1-beta.8

2 years ago

1.9.1

2 years ago

1.9.50

2 years ago

1.9.49

2 years ago

1.9.48

2 years ago

1.9.47

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.46

2 years ago

1.4.44

2 years ago

1.4.0

2 years ago

1.4.43

2 years ago

1.3.42

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.1.0

2 years ago

0.1.41

2 years ago

0.1.40

2 years ago