2.0.13 • Published 2 years ago
@flexbase/http-client-middleware v2.0.13
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
2 years ago
2.0.2
2 years ago
2.0.13
2 years ago
2.0.12
2 years ago
2.0.3-beta.12
2 years ago
1.10.0-beta.1
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.9.4
3 years ago
1.9.3
3 years ago
1.9.55
3 years ago
1.9.2
3 years ago
1.9.1-beta.25
3 years ago
1.9.1-beta.24
3 years ago
0.0.0
3 years ago
1.9.1-beta.8
3 years ago
1.9.1
3 years ago
1.9.50
3 years ago
1.9.49
3 years ago
1.9.48
3 years ago
1.9.47
3 years ago
1.9.0
3 years ago
1.8.0
3 years ago
1.7.0
3 years ago
1.6.0
3 years ago
1.5.0
3 years ago
1.4.46
3 years ago
1.4.44
3 years ago
1.4.0
3 years ago
1.4.43
3 years ago
1.3.42
3 years ago
1.3.0
3 years ago
1.2.0
3 years ago
1.1.0
3 years ago
1.0.0
3 years ago
0.1.0
3 years ago
0.1.41
3 years ago
0.1.40
3 years ago