mirror of https://github.com/abpframework/abp.git
committed by
GitHub
13 changed files with 304 additions and 16 deletions
@ -0,0 +1,40 @@ |
|||||
|
import { AuthErrorEvent, AuthErrorFilter } from '../models'; |
||||
|
|
||||
|
export abstract class AbstractAuthErrorFilter<T, E> { |
||||
|
abstract get(id: string): T; |
||||
|
abstract add(filter: T): void; |
||||
|
abstract patch(item: Partial<T>): void; |
||||
|
abstract remove(id: string): void; |
||||
|
abstract run(event: E): boolean; |
||||
|
} |
||||
|
|
||||
|
export class AuthErrorFilterService< |
||||
|
T = AuthErrorFilter, |
||||
|
E = AuthErrorEvent, |
||||
|
> extends AbstractAuthErrorFilter<T, E> { |
||||
|
private warningMessage() { |
||||
|
console.error('You should add @abp/ng-oauth packages or create your own auth packages.'); |
||||
|
} |
||||
|
|
||||
|
get(id: string): T { |
||||
|
this.warningMessage(); |
||||
|
throw new Error('not implemented'); |
||||
|
} |
||||
|
|
||||
|
add(filter: T): void { |
||||
|
this.warningMessage(); |
||||
|
} |
||||
|
|
||||
|
patch(item: Partial<T>): void { |
||||
|
this.warningMessage(); |
||||
|
} |
||||
|
|
||||
|
remove(id: string): void { |
||||
|
this.warningMessage(); |
||||
|
} |
||||
|
|
||||
|
run(event: E): boolean { |
||||
|
this.warningMessage(); |
||||
|
throw new Error('not implemented'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
export type EventType = |
||||
|
| 'discovery_document_loaded' |
||||
|
| 'jwks_load_error' |
||||
|
| 'invalid_nonce_in_state' |
||||
|
| 'discovery_document_load_error' |
||||
|
| 'discovery_document_validation_error' |
||||
|
| 'user_profile_loaded' |
||||
|
| 'user_profile_load_error' |
||||
|
| 'token_received' |
||||
|
| 'token_error' |
||||
|
| 'code_error' |
||||
|
| 'token_refreshed' |
||||
|
| 'token_refresh_error' |
||||
|
| 'silent_refresh_error' |
||||
|
| 'silently_refreshed' |
||||
|
| 'silent_refresh_timeout' |
||||
|
| 'token_validation_error' |
||||
|
| 'token_expires' |
||||
|
| 'session_changed' |
||||
|
| 'session_error' |
||||
|
| 'session_terminated' |
||||
|
| 'session_unchanged' |
||||
|
| 'logout' |
||||
|
| 'popup_closed' |
||||
|
| 'popup_blocked' |
||||
|
| 'token_revoke_error'; |
||||
|
|
||||
|
export abstract class AuthEvent { |
||||
|
constructor(public readonly type: EventType) { |
||||
|
this.type = type; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export class AuthSuccessEvent extends AuthEvent { |
||||
|
constructor(public readonly type: EventType, public readonly info?: any) { |
||||
|
super(type); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export class AuthInfoEvent extends AuthEvent { |
||||
|
constructor(public readonly type: EventType, public readonly info?: any) { |
||||
|
super(type); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export class AuthErrorEvent extends AuthEvent { |
||||
|
constructor( |
||||
|
public readonly type: EventType, |
||||
|
public readonly reason: object, |
||||
|
public readonly params?: object, |
||||
|
) { |
||||
|
super(type); |
||||
|
} |
||||
|
} |
||||
@ -1 +1,2 @@ |
|||||
export * from './oauth.service'; |
export * from './oauth.service'; |
||||
|
export * from './oauth-error-filter.service'; |
||||
|
|||||
@ -0,0 +1,45 @@ |
|||||
|
import { Injectable, signal } from '@angular/core'; |
||||
|
import { OAuthErrorEvent } from 'angular-oauth2-oidc'; |
||||
|
import { AbstractAuthErrorFilter, AuthErrorFilter } from '@abp/ng.core'; |
||||
|
|
||||
|
@Injectable({ providedIn: 'root' }) |
||||
|
export class OAuthErrorFilterService extends AbstractAuthErrorFilter< |
||||
|
AuthErrorFilter<OAuthErrorEvent>, |
||||
|
OAuthErrorEvent |
||||
|
> { |
||||
|
protected readonly _filters = signal<Array<AuthErrorFilter<OAuthErrorEvent>>>([]); |
||||
|
readonly filters = this._filters.asReadonly(); |
||||
|
|
||||
|
get(id: string): AuthErrorFilter<OAuthErrorEvent> { |
||||
|
return this._filters().find(({ id: _id }) => _id === id); |
||||
|
} |
||||
|
|
||||
|
add(filter: AuthErrorFilter<OAuthErrorEvent>): void { |
||||
|
this._filters.update(items => [...items, filter]); |
||||
|
} |
||||
|
|
||||
|
patch(item: Partial<AuthErrorFilter<OAuthErrorEvent>>): void { |
||||
|
const _item = this.filters().find(({ id }) => id === item.id); |
||||
|
if (!_item) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
Object.assign(_item, item); |
||||
|
} |
||||
|
|
||||
|
remove(id: string): void { |
||||
|
const item = this.filters().find(({ id: _id }) => _id === id); |
||||
|
if (!item) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
this._filters.update(items => items.filter(({ id: _id }) => _id !== id)); |
||||
|
} |
||||
|
|
||||
|
run(event: OAuthErrorEvent): boolean { |
||||
|
return this.filters() |
||||
|
.filter(({ executable }) => !!executable) |
||||
|
.map(({ execute }) => execute(event)) |
||||
|
.some(item => item); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue