http-client-middle 软件
这是一个包裹 http 认证的中间软件包 .
使用量
使用 烂透了
客户证书
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]);
密码证书
// 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]);