@adatechnology/auth-keycloak 0.0.3 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +114 -6
- package/dist/index.js +743 -16
- package/package.json +6 -6
- package/dist/errors/keycloak-error.d.ts +0 -11
- package/dist/errors/keycloak-error.js +0 -20
- package/dist/errors/keycloak-error.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keycloak.client.d.ts +0 -27
- package/dist/keycloak.client.js +0 -320
- package/dist/keycloak.client.js.map +0 -1
- package/dist/keycloak.http.interceptor.d.ts +0 -9
- package/dist/keycloak.http.interceptor.js +0 -37
- package/dist/keycloak.http.interceptor.js.map +0 -1
- package/dist/keycloak.interface.d.ts +0 -74
- package/dist/keycloak.interface.js +0 -3
- package/dist/keycloak.interface.js.map +0 -1
- package/dist/keycloak.module.d.ts +0 -6
- package/dist/keycloak.module.js +0 -63
- package/dist/keycloak.module.js.map +0 -1
- package/dist/keycloak.token.d.ts +0 -3
- package/dist/keycloak.token.js +0 -7
- package/dist/keycloak.token.js.map +0 -1
- package/dist/roles.decorator.d.ts +0 -19
- package/dist/roles.decorator.js +0 -34
- package/dist/roles.decorator.js.map +0 -1
- package/dist/roles.guard.d.ts +0 -10
- package/dist/roles.guard.js +0 -103
- package/dist/roles.guard.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as _nestjs_common from '@nestjs/common';
|
|
2
|
+
import { DynamicModule, CanActivate, ExecutionContext } from '@nestjs/common';
|
|
3
|
+
import { AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
4
|
+
import { Reflector } from '@nestjs/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Keycloak token response
|
|
8
|
+
*/
|
|
9
|
+
interface KeycloakTokenResponse {
|
|
10
|
+
access_token: string;
|
|
11
|
+
expires_in: number;
|
|
12
|
+
refresh_expires_in: number;
|
|
13
|
+
refresh_token: string;
|
|
14
|
+
token_type: string;
|
|
15
|
+
"not-before-policy": number;
|
|
16
|
+
session_state: string;
|
|
17
|
+
scope: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Keycloak client credentials
|
|
21
|
+
*/
|
|
22
|
+
interface KeycloakCredentials {
|
|
23
|
+
clientId: string;
|
|
24
|
+
clientSecret: string;
|
|
25
|
+
username?: string;
|
|
26
|
+
password?: string;
|
|
27
|
+
grantType: "client_credentials" | "password";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Keycloak configuration
|
|
31
|
+
*/
|
|
32
|
+
interface KeycloakConfig {
|
|
33
|
+
baseUrl: string;
|
|
34
|
+
realm: string;
|
|
35
|
+
credentials: KeycloakCredentials;
|
|
36
|
+
/**
|
|
37
|
+
* Optional scopes to request when fetching tokens. Can be a space-separated string or array of scopes.
|
|
38
|
+
* Defaults to ['openid', 'profile', 'email'] when omitted.
|
|
39
|
+
*/
|
|
40
|
+
scopes?: string | string[];
|
|
41
|
+
/**
|
|
42
|
+
* Optional token cache TTL in milliseconds. If provided, KeycloakClient will use this value to
|
|
43
|
+
* determine how long to cache the access token instead of deriving TTL from the token's expires_in.
|
|
44
|
+
*/
|
|
45
|
+
tokenCacheTtl?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Keycloak client interface
|
|
49
|
+
*/
|
|
50
|
+
interface KeycloakClientInterface {
|
|
51
|
+
/**
|
|
52
|
+
* Get access token
|
|
53
|
+
*/
|
|
54
|
+
getAccessToken(): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Refresh access token
|
|
57
|
+
*/
|
|
58
|
+
refreshToken(refreshToken: string): Promise<KeycloakTokenResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Validate token
|
|
61
|
+
*/
|
|
62
|
+
validateToken(token: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Get user info
|
|
65
|
+
*/
|
|
66
|
+
getUserInfo(token: string): Promise<Record<string, unknown>>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare class KeycloakModule {
|
|
70
|
+
static forRoot(config: KeycloakConfig, httpConfig?: AxiosRequestConfig | AxiosInstance): DynamicModule;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare const KEYCLOAK_CONFIG = "KEYCLOAK_CONFIG";
|
|
74
|
+
declare const KEYCLOAK_CLIENT = "KEYCLOAK_CLIENT";
|
|
75
|
+
declare const KEYCLOAK_HTTP_INTERCEPTOR = "KEYCLOAK_HTTP_INTERCEPTOR";
|
|
76
|
+
|
|
77
|
+
type RolesMode = "any" | "all";
|
|
78
|
+
type RolesType = "realm" | "client" | "both";
|
|
79
|
+
type RolesOptions = {
|
|
80
|
+
roles: string[];
|
|
81
|
+
mode?: RolesMode;
|
|
82
|
+
type?: RolesType;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Decorator to declare required roles for a route or controller.
|
|
86
|
+
* Accepts either a list of strings or a single options object.
|
|
87
|
+
* Examples:
|
|
88
|
+
* @Roles('admin')
|
|
89
|
+
* @Roles('admin','editor')
|
|
90
|
+
* @Roles(['admin','editor'])
|
|
91
|
+
* @Roles({ roles: ['a','b'], mode: 'all', type: 'client' })
|
|
92
|
+
*/
|
|
93
|
+
declare function Roles(...args: Array<string | string[] | RolesOptions>): _nestjs_common.CustomDecorator<string>;
|
|
94
|
+
|
|
95
|
+
declare class RolesGuard implements CanActivate {
|
|
96
|
+
private readonly reflector;
|
|
97
|
+
private readonly config?;
|
|
98
|
+
constructor(reflector: Reflector, config?: KeycloakConfig);
|
|
99
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean>;
|
|
100
|
+
private decodeJwtPayload;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare class KeycloakError extends Error {
|
|
104
|
+
readonly statusCode?: number;
|
|
105
|
+
readonly details?: unknown;
|
|
106
|
+
readonly keycloakError?: string;
|
|
107
|
+
constructor(message: string, opts?: {
|
|
108
|
+
statusCode?: number;
|
|
109
|
+
details?: unknown;
|
|
110
|
+
keycloakError?: string;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { KEYCLOAK_CLIENT, KEYCLOAK_CONFIG, KEYCLOAK_HTTP_INTERCEPTOR, type KeycloakClientInterface, type KeycloakConfig, KeycloakError, KeycloakModule, type KeycloakTokenResponse, Roles, RolesGuard };
|