Skip to content

Commit

Permalink
docs: updae
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 12, 2023
1 parent 914a6c2 commit 1f23245
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 49 deletions.
1 change: 1 addition & 0 deletions packages/auth/docs/getting-started.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Configure the `provideAuth` environment in `app.config.ts`:

```typescript
providers: [
// Indicates using JWT style and using `localStorage` to store Token
provideAuth(withJWT(), withLocalStorage()),
]
```
Expand Down
1 change: 1 addition & 0 deletions packages/auth/docs/getting-started.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ npm i -S @delon/auth

```typescript
providers: [
// 表示使用JWT风格并用 `localStorage` 存储 Token
provideAuth(withJWT(), withLocalStorage()),
]
```
Expand Down
13 changes: 7 additions & 6 deletions packages/auth/docs/send.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type: Documents

It is better to add the corresponding authentication information to each request through the HTTP interceptor. `@delonn/auth` implements two separate HTTP interceptors based on two different authentication styles.

### withAuthSimple
### withSimple

The parameter name and its sending location can be specified via `DelonAuthConfig`, for example:

Expand All @@ -22,24 +22,25 @@ token_send_place = 'header';

Indicates the `{ token: 'Bearer token_string' }` data in the `header` of each request.

### withAuthJWT
### withJWT

It is a standard JWT sending rule that automatically adds `{ Authorization: 'Bearer token_string' }` to `header`.

### How to choose?

`withAuthSimple` is a very liberal style, you can put `token` in the request body, request header, etc.
`withSimple` is a very liberal style, you can put `token` in the request body, request header, etc.

`withAuthJWT` is a JWT standard, which needs to ensure that the backend also uses such standards.
`withJWT` is a JWT standard, which needs to ensure that the backend also uses such standards.

## How to load

In `app.config.ts` file:

```ts
providers: [
withAuthSimple(),
// or withAuthSimple()
provideAuth(withSimple()),
// Or JWT
provideAuth(withJWT()),
]
```

Expand Down
13 changes: 7 additions & 6 deletions packages/auth/docs/send.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type: Documents

通过HTTP拦截器在每一个请求中加入相应的认证信息,这是再好不过。`@delonn/auth` 根据两种不同认证风格,实现两种各自的HTTP拦截器。

### withAuthSimple
### withSimple

透过 `DelonAuthConfig` 可以指定参数名以及其发送位置,例如:

Expand All @@ -20,24 +20,25 @@ token_send_place = 'header';

表示在每一个请求的 `header` 加上 `{ token: 'Bearer token_string' }` 数据。

### withAuthJWT
### withJWT

它是一个标准JWT的发送规则,即在 `header` 自动加上 `{ Authorization: 'Bearer token_string' }`

### 如何选择?

`withAuthSimple` 是一种自由度非常高的风格,你可以将 `token` 放在请求体、请求头等当中。
`withSimple` 是一种自由度非常高的风格,你可以将 `token` 放在请求体、请求头等当中。

`withAuthJWT` 是一个 JWT 标准,这需要确保后端也采用这类标准。
`withJWT` 是一个 JWT 标准,这需要确保后端也采用这类标准。

## 如何加载

`app.config.ts` 加入:

```ts
providers: [
withAuthSimple(),
// or withAuthSimple()
provideAuth(withSimple()),
// Or JWT
provideAuth(withJWT()),
]
```

Expand Down
25 changes: 9 additions & 16 deletions packages/auth/docs/set.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,28 @@ constructor(@Inject(DA_SERVICE_TOKEN) service: ITokenService) {

## Storage type

The default is to use `LocalStorageStore` persistent storage, you can change other storage methods in `global-config.module.ts` or root module.
The default is to use `withLocalStorage` persistent storage. You can change other storage methods in `app.config.ts`.

```ts
export class GlobalConfigModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: GlobalConfigModule,
providers: [
{ provide: DA_STORE_TOKEN, useClass: MemoryStore }
]
};
}
}
providers: [
provideAuth(withJWT(), withLocalStorage()),
]
```

Contains three storage types:

### LocalStorageStore
### withLocalStorage

`localStorage` storage, **not lost after closing the browser**.

### SessionStorageStore
### withSessionStorage

`sessionStorage` storage, **lost after closing the browser**.

### MemoryStore
### withMemoryStorage

Memory storage, **lost after closing the browser tab**.

### CookieStorageStore
### withCookie

`cookie` storage.
`cookie` storage.
23 changes: 8 additions & 15 deletions packages/auth/docs/set.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,28 @@ constructor(@Inject(DA_SERVICE_TOKEN) service: ITokenService) {

## 存储类型

默认是采用 `LocalStorageStore` 持久化存储,你可以在 `global-config.module.ts` 或根模块里变更其他存储方式
默认是采用 `withLocalStorage` 持久化存储,你可以在 `app.config.ts` 变更其他存储方式

```ts
export class GlobalConfigModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: GlobalConfigModule,
providers: [
{ provide: DA_STORE_TOKEN, useClass: MemoryStore }
]
};
}
}
providers: [
provideAuth(withJWT(), withLocalStorage()),
]
```

包含三种存储类型:

### LocalStorageStore
### withLocalStorage

`localStorage` 存储,关掉浏览器后**不丢失**

### SessionStorageStore
### withSessionStorage

`sessionStorage` 存储,关掉浏览器后**丢失**

### MemoryStore
### withMemoryStorage

内存存储,关掉浏览器标签后**丢失**

### CookieStorageStore
### withCookie

Cookie 存储。
7 changes: 6 additions & 1 deletion packages/auth/src/provide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EnvironmentProviders, Provider, makeEnvironmentProviders } from '@angul

import { CookieService } from '@delon/util/browser';

import { CookieStorageStore, DA_STORE_TOKEN, LocalStorageStore, SessionStorageStore } from './store';
import { CookieStorageStore, DA_STORE_TOKEN, LocalStorageStore, MemoryStore, SessionStorageStore } from './store';
import { JWTInterceptor, SimpleInterceptor } from './token/index';

export enum AuthFeatureKind {
Expand Down Expand Up @@ -76,3 +76,8 @@ export function withLocalStorage(): AuthFeature<AuthFeatureKind.Store> {
export function withSessionStorage(): AuthFeature<AuthFeatureKind.Store> {
return makeAuthFeature(AuthFeatureKind.Store, [{ provide: DA_STORE_TOKEN, useClass: SessionStorageStore }]);
}

/** Memory storage, **lost after closing the browser tab**. */
export function withMemoryStorage(): AuthFeature<AuthFeatureKind.Store> {
return makeAuthFeature(AuthFeatureKind.Store, [{ provide: DA_STORE_TOKEN, useClass: MemoryStore }]);
}
5 changes: 0 additions & 5 deletions packages/auth/src/store/memory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import { ITokenModel } from '../token/interface';

/**
* 内存存储,关掉浏览器标签后**丢失**。
*
* ```ts
* // global-config.module.ts
* { provide: DA_STORE_TOKEN, useClass: MemoryStore }
* ```
*/
export class MemoryStore implements IStore {
private cache: { [key: string]: ITokenModel | null } = {};
Expand Down

0 comments on commit 1f23245

Please sign in to comment.