@adatechnology/auth-keycloak 0.0.3 → 0.0.7

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 CHANGED
@@ -1,6 +1,132 @@
1
- export { KeycloakModule } from "./keycloak.module";
2
- export { KEYCLOAK_CONFIG, KEYCLOAK_CLIENT, KEYCLOAK_HTTP_INTERCEPTOR, } from "./keycloak.token";
3
- export type { KeycloakConfig, KeycloakClientInterface, KeycloakTokenResponse, } from "./keycloak.interface";
4
- export { Roles } from "./roles.decorator";
5
- export { RolesGuard } from "./roles.guard";
6
- export { KeycloakError } from "./errors/keycloak-error";
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
+ * Obtain a token using resource-owner credentials (username/password).
57
+ * Returns the full Keycloak token response so callers can access refresh tokens and other fields.
58
+ */
59
+ getTokenWithCredentials(params: {
60
+ username: string;
61
+ password: string;
62
+ }): Promise<KeycloakTokenResponse>;
63
+ /**
64
+ * Refresh access token
65
+ */
66
+ refreshToken(refreshToken: string): Promise<KeycloakTokenResponse>;
67
+ /**
68
+ * Validate token
69
+ */
70
+ validateToken(token: string): Promise<boolean>;
71
+ /**
72
+ * Get user info
73
+ */
74
+ getUserInfo(token: string): Promise<Record<string, unknown>>;
75
+ /**
76
+ * Clear the internal access token cache maintained by the client.
77
+ */
78
+ clearTokenCache(): void;
79
+ }
80
+ /**
81
+ * Provider-facing interface type to be used when injecting the keycloak provider token.
82
+ * Exported separately to make the intended injection type explicit.
83
+ */
84
+ type KeycloakProviderInterface = KeycloakClientInterface;
85
+
86
+ declare class KeycloakModule {
87
+ static forRoot(config: KeycloakConfig, httpConfig?: AxiosRequestConfig | AxiosInstance): DynamicModule;
88
+ }
89
+
90
+ declare const KEYCLOAK_CONFIG = "KEYCLOAK_CONFIG";
91
+ declare const KEYCLOAK_CLIENT = "KEYCLOAK_CLIENT";
92
+ declare const KEYCLOAK_HTTP_INTERCEPTOR = "KEYCLOAK_HTTP_INTERCEPTOR";
93
+ declare const KEYCLOAK_PROVIDER = "KEYCLOAK_PROVIDER";
94
+
95
+ type RolesMode = "any" | "all";
96
+ type RolesType = "realm" | "client" | "both";
97
+ type RolesOptions = {
98
+ roles: string[];
99
+ mode?: RolesMode;
100
+ type?: RolesType;
101
+ };
102
+ /**
103
+ * Decorator to declare required roles for a route or controller.
104
+ * Accepts either a list of strings or a single options object.
105
+ * Examples:
106
+ * @Roles('admin')
107
+ * @Roles('admin','editor')
108
+ * @Roles(['admin','editor'])
109
+ * @Roles({ roles: ['a','b'], mode: 'all', type: 'client' })
110
+ */
111
+ declare function Roles(...args: Array<string | string[] | RolesOptions>): _nestjs_common.CustomDecorator<string>;
112
+
113
+ declare class RolesGuard implements CanActivate {
114
+ private readonly reflector;
115
+ private readonly config?;
116
+ constructor(reflector: Reflector, config?: KeycloakConfig);
117
+ canActivate(context: ExecutionContext): boolean | Promise<boolean>;
118
+ private decodeJwtPayload;
119
+ }
120
+
121
+ declare class KeycloakError extends Error {
122
+ readonly statusCode?: number;
123
+ readonly details?: unknown;
124
+ readonly keycloakError?: string;
125
+ constructor(message: string, opts?: {
126
+ statusCode?: number;
127
+ details?: unknown;
128
+ keycloakError?: string;
129
+ });
130
+ }
131
+
132
+ export { KEYCLOAK_CLIENT, KEYCLOAK_CONFIG, KEYCLOAK_HTTP_INTERCEPTOR, KEYCLOAK_PROVIDER, type KeycloakClientInterface, type KeycloakConfig, KeycloakError, KeycloakModule, type KeycloakProviderInterface, type KeycloakTokenResponse, Roles, RolesGuard };