@ackee/antonio-auth 中文文档教程
@ackee/antonio-auth
它包含一个用于设置 Authorization
的 @ackee/antonio-core
的请求拦截器带有从 @ackee/petrus
的 getAccessToken
获得的访问令牌的标头。
Table of contents
Install
yarn add @ackee/antonio-auth -S
# Check you have installed at least these dependencies' versions:
yarn add @ackee/petrus@5.2.1
API
requestAuthHeaderInterceptor(request: Request): Request
一个请求拦截器,它使用 @ackee/antonio-utils
中的 setAuthHeader
设置 Authorization
标头,并从 getAccessToken
中获取<代码>@ackee/petrus。
Default usage example
import { Antonio } from '@ackee/antonio-core';
import { requestAuthHeaderInterceptor } from '@ackee/antonio-auth';
const api = new Antonio({
baseURL: '...',
});
api.interceptors.request.use(null, requestAuthHeaderInterceptor);
Custom usage example (without @ackee/petrus)
import { Antonio } from '@ackee/antonio-core';
import { setAuthHeader } from '@ackee/antonio-utils';
const api = new Antonio({
baseURL: '...',
});
function* getAccessToken() {
// Your custom function for obtaining the access token.
}
api.interceptors.request.use(null, function* (request) {
const accessToken = yield getAccessToken();
setAuthHeader(requst.headers, accessToken);
return request;
});
@ackee/antonio-auth
It includes a request interceptor for @ackee/antonio-core
that sets the Authorization
header with an access token obtained from getAccessToken
from @ackee/petrus
.
Table of contents
Install
yarn add @ackee/antonio-auth -S
# Check you have installed at least these dependencies' versions:
yarn add @ackee/petrus@5.2.1
API
requestAuthHeaderInterceptor(request: Request): Request
A request interceptor that sets the Authorization
header with setAuthHeader
from @ackee/antonio-utils
and obtained from getAccessToken
from @ackee/petrus
.
Default usage example
import { Antonio } from '@ackee/antonio-core';
import { requestAuthHeaderInterceptor } from '@ackee/antonio-auth';
const api = new Antonio({
baseURL: '...',
});
api.interceptors.request.use(null, requestAuthHeaderInterceptor);
Custom usage example (without @ackee/petrus)
import { Antonio } from '@ackee/antonio-core';
import { setAuthHeader } from '@ackee/antonio-utils';
const api = new Antonio({
baseURL: '...',
});
function* getAccessToken() {
// Your custom function for obtaining the access token.
}
api.interceptors.request.use(null, function* (request) {
const accessToken = yield getAccessToken();
setAuthHeader(requst.headers, accessToken);
return request;
});
更多
你可能也喜欢
- 40banner 中文文档教程
- @11ty/eleventy-plugin-syntaxhighlight 中文文档教程
- @12core/date-input-polyfill 中文文档教程
- @1password/xplatform-web 中文文档教程
- @4th-law/typings-public 中文文档教程
- @ab.progr/prettier-config 中文文档教程
- @abb-cli/core 中文文档教程
- @abcnews/capi-fetch 中文文档教程
- @abhijoseph/newman-reporter-reportportal 中文文档教程
- @abstractsins/test 中文文档教程