@opengeoweb/authentication 19.1.0 → 19.2.0
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/README.md +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1190 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/lib/components/ApiContext/index.d.ts +2 -0
- package/dist/src/lib/components/ApiContext/types.d.ts +35 -0
- package/dist/src/lib/components/ApiContext/utils.d.ts +27 -0
- package/dist/src/lib/components/AuthenticationContext/AuthenticationContext.d.ts +19 -0
- package/dist/src/lib/components/AuthenticationContext/AuthenticationRenderTestComponent.d.ts +10 -0
- package/dist/src/lib/components/AuthenticationContext/index.d.ts +2 -0
- package/dist/src/lib/components/AuthenticationContext/types.d.ts +25 -0
- package/dist/src/lib/components/Providers/Providers.d.ts +7 -0
- package/dist/src/lib/components/Providers/index.d.ts +1 -0
- package/dist/src/lib/components/UserMenuRoles/UserMenuRoles.d.ts +7 -0
- package/dist/src/lib/components/UserMenuRoles/index.d.ts +1 -0
- package/dist/src/lib/components/apiHooks/index.d.ts +1 -0
- package/dist/src/lib/components/apiHooks/useApi.d.ts +36 -0
- package/dist/src/lib/components/pages/Code.d.ts +4 -0
- package/dist/src/lib/components/pages/Login.d.ts +3 -0
- package/dist/src/lib/components/pages/Logout.d.ts +3 -0
- package/dist/src/lib/components/pages/index.d.ts +3 -0
- package/dist/src/lib/utils/i18n.d.ts +6 -0
- package/dist/src/lib/utils/mockdata.d.ts +11 -0
- package/dist/src/lib/utils/utils.d.ts +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import apiTranslations from '../locales/api.json';
|
|
2
|
+
import authTranslations from '../locales/authentication.json';
|
|
3
|
+
export { default as Code } from './lib/components/pages/Code';
|
|
4
|
+
export { default as Login } from './lib/components/pages/Login';
|
|
5
|
+
export { default as Logout } from './lib/components/pages/Logout';
|
|
6
|
+
export * from './lib/components/UserMenuRoles';
|
|
7
|
+
export * from './lib/components/AuthenticationContext';
|
|
8
|
+
export * from './lib/components/ApiContext';
|
|
9
|
+
export * from './lib/components/apiHooks';
|
|
10
|
+
export * from './lib/utils/utils';
|
|
11
|
+
export { AUTH_NAMESPACE } from './lib/utils/i18n';
|
|
12
|
+
export { authTranslations, apiTranslations };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface GeoWebJWT {
|
|
2
|
+
access_token: string;
|
|
3
|
+
refresh_token?: string;
|
|
4
|
+
id_token: string;
|
|
5
|
+
expires_in: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Credentials {
|
|
8
|
+
username: string;
|
|
9
|
+
roles?: Role[];
|
|
10
|
+
token: string;
|
|
11
|
+
refresh_token: string;
|
|
12
|
+
expires_at?: number;
|
|
13
|
+
has_connection_issue?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface ApiUrls {
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
appURL?: string;
|
|
18
|
+
authTokenURL?: string;
|
|
19
|
+
authClientId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ApiModule {
|
|
22
|
+
auth?: Credentials;
|
|
23
|
+
onSetAuth?: (cred: Credentials) => void;
|
|
24
|
+
config?: ApiUrls;
|
|
25
|
+
name?: string;
|
|
26
|
+
onLogin?: (isLoggedIn: boolean) => void;
|
|
27
|
+
}
|
|
28
|
+
export interface CreateApiProps extends ApiModule {
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
export type CreateApiFn = (props: CreateApiProps) => unknown;
|
|
32
|
+
export interface Role {
|
|
33
|
+
name: string;
|
|
34
|
+
title: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
import type { ConfigType } from '@opengeoweb/shared';
|
|
3
|
+
import type { CreateApiProps, Credentials, Role } from './types';
|
|
4
|
+
export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 60;
|
|
5
|
+
export declare const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75;
|
|
6
|
+
export declare const MILLISECOND_TO_SECOND: number;
|
|
7
|
+
export declare const GEOWEB_ROLE_PRESETS_ADMIN: Role;
|
|
8
|
+
export declare const GEOWEB_ROLE_USER: Role;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Credentials object based on the axios response from the token service.
|
|
11
|
+
*
|
|
12
|
+
* It will calculate the expires_at attribute based on the expires_in property found in the JWT.
|
|
13
|
+
*
|
|
14
|
+
* @param tokenResponse Response of the tokenservice as axios response object.
|
|
15
|
+
* @returns Credentials object.
|
|
16
|
+
*/
|
|
17
|
+
export declare const makeCredentialsFromTokenResponse: (tokenResponse: AxiosResponse, authConfig?: ConfigType) => Credentials;
|
|
18
|
+
export declare const refreshAccessToken: ({ auth, config: { authTokenURL, authClientId, appURL }, timeout, }: CreateApiProps) => Promise<AxiosResponse>;
|
|
19
|
+
export declare const refreshAccessTokenAndSetAuthContext: ({ auth, onSetAuth, config, timeout, configURLS, onLogin, }: CreateApiProps & {
|
|
20
|
+
configURLS?: ConfigType;
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
export declare const createApiInstance: ({ auth, config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
|
|
23
|
+
export declare const createNonAuthApiInstance: ({ config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
|
|
24
|
+
export declare const fakeApiRequest: (signal?: AbortController) => Promise<void>;
|
|
25
|
+
export declare const createFakeApiInstance: () => AxiosInstance;
|
|
26
|
+
export declare const getCurrentTimeInSeconds: () => number;
|
|
27
|
+
export declare const groupsToRoles: (groups: string[] | undefined, authConfig?: ConfigType) => Role[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AuthenticationConfig, AuthenticationContextProps, AuthenticationDefaultStateProps } from './types';
|
|
3
|
+
import type { Credentials } from '../ApiContext/types';
|
|
4
|
+
export declare const getRandomString: () => string;
|
|
5
|
+
export declare const getCodeChallenge: (codeVerifier: string) => Promise<string>;
|
|
6
|
+
export declare const replaceTemplateKeys: (url: string, clientId: string, appUrl: string, oauthState?: string, codeChallenge?: string) => string;
|
|
7
|
+
export declare const getAuthConfig: (_configUrls: AuthenticationConfig) => AuthenticationConfig;
|
|
8
|
+
export declare const AuthenticationContext: React.Context<AuthenticationContextProps>;
|
|
9
|
+
type OnAuthChange = (isLoggedIn: boolean, auth: Credentials | null) => void;
|
|
10
|
+
export declare const setAuthChangeListener: (listener: OnAuthChange) => void;
|
|
11
|
+
export declare const useAuthenticationDefaultProps: () => AuthenticationDefaultStateProps;
|
|
12
|
+
export interface AuthenticationProviderProps {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
value?: AuthenticationDefaultStateProps;
|
|
15
|
+
configURLS?: AuthenticationConfig;
|
|
16
|
+
}
|
|
17
|
+
export declare const AuthenticationProvider: React.FC<AuthenticationProviderProps>;
|
|
18
|
+
export declare const useAuthenticationContext: () => AuthenticationContextProps;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Credentials } from '../ApiContext/types';
|
|
3
|
+
interface AuthenticationRenderTestComponentProps {
|
|
4
|
+
auth: Credentials | null;
|
|
5
|
+
newAuth: Credentials;
|
|
6
|
+
onSetAuth: (auth: Credentials) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const resetNumRenders: () => void;
|
|
9
|
+
declare const AuthenticationRenderTestComponent: React.FC<AuthenticationRenderTestComponentProps>;
|
|
10
|
+
export default AuthenticationRenderTestComponent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SessionStorageProvider } from '@opengeoweb/shared';
|
|
2
|
+
import type { Credentials, Role } from '../ApiContext/types';
|
|
3
|
+
export interface AuthenticationConfig {
|
|
4
|
+
GW_AUTH_LOGIN_URL: string;
|
|
5
|
+
GW_AUTH_LOGOUT_URL: string;
|
|
6
|
+
GW_AUTH_TOKEN_URL: string;
|
|
7
|
+
GW_AUTH_ROLE_CLAIM_NAME?: string;
|
|
8
|
+
GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN?: string;
|
|
9
|
+
GW_APP_URL: string;
|
|
10
|
+
GW_BE_VERSION_BASE_URL?: string;
|
|
11
|
+
GW_AUTH_CLIENT_ID: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AuthenticationDefaultStateProps {
|
|
14
|
+
isLoggedIn: boolean;
|
|
15
|
+
onLogin: (isLoggedIn: boolean) => void;
|
|
16
|
+
auth: Credentials | null;
|
|
17
|
+
onSetAuth: (auth: Credentials) => void;
|
|
18
|
+
sessionStorageProvider: SessionStorageProvider;
|
|
19
|
+
currentRole?: Role;
|
|
20
|
+
setCurrentRole?: (newRole: Role) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface AuthenticationContextProps extends AuthenticationDefaultStateProps {
|
|
23
|
+
authConfig: AuthenticationConfig;
|
|
24
|
+
}
|
|
25
|
+
export type AuthChangeListener = (isLoggedIn: boolean, auth: Credentials | null) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface AuthTranslationWrapperProps {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare const AuthI18nProvider: React.FC<AuthTranslationWrapperProps>;
|
|
6
|
+
export declare const DemoWrapper: React.FC<AuthTranslationWrapperProps>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Providers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UserMenuRoles } from './UserMenuRoles';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useApi } from './useApi';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ConfigType } from '@opengeoweb/shared';
|
|
2
|
+
export type ApiParams = string | ConfigType | Record<string, string | undefined> | null;
|
|
3
|
+
interface BaseApiHookProps {
|
|
4
|
+
fetchApiData?: (params: ApiParams) => Promise<void>;
|
|
5
|
+
clearResults?: () => void;
|
|
6
|
+
}
|
|
7
|
+
type PendingApiHookProps = BaseApiHookProps & {
|
|
8
|
+
isLoading: true;
|
|
9
|
+
result: null;
|
|
10
|
+
error: null;
|
|
11
|
+
};
|
|
12
|
+
type DoneApiHookProps<R> = BaseApiHookProps & {
|
|
13
|
+
isLoading: false;
|
|
14
|
+
result: R;
|
|
15
|
+
error: null;
|
|
16
|
+
};
|
|
17
|
+
type ErrorApiHookProps = BaseApiHookProps & {
|
|
18
|
+
isLoading: false;
|
|
19
|
+
result: null;
|
|
20
|
+
error: Error;
|
|
21
|
+
};
|
|
22
|
+
export type ApiHookProps<TData> = ErrorApiHookProps | PendingApiHookProps | DoneApiHookProps<TData>;
|
|
23
|
+
interface Callbacks<TData> {
|
|
24
|
+
onSuccess?: (data: TData) => void;
|
|
25
|
+
onError?: (e: Error) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare const useApi: <TResponse extends {
|
|
28
|
+
data: unknown;
|
|
29
|
+
} | {
|
|
30
|
+
data: unknown;
|
|
31
|
+
}[], TResult = TResponse extends {
|
|
32
|
+
data: infer TData;
|
|
33
|
+
}[] ? TData[] : TResponse extends {
|
|
34
|
+
data: infer TData_1;
|
|
35
|
+
} ? TData_1 : never>(apiCall?: (params?: any, id?: string) => Promise<TResponse>, params?: any, callbacks?: Callbacks<TResult>) => ApiHookProps<TResult>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import i18n from 'i18next';
|
|
2
|
+
import type { UseTranslationResponse } from 'react-i18next';
|
|
3
|
+
export declare const AUTH_NAMESPACE = "auth";
|
|
4
|
+
export declare const initAuthTestI18n: () => void;
|
|
5
|
+
export declare const useAuthenticationTranslation: () => UseTranslationResponse<typeof AUTH_NAMESPACE, typeof i18n>;
|
|
6
|
+
export declare const translateInTestsAndStories: (key: string, params?: Record<string, string | number> | undefined) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const mockloginSuccess: {
|
|
2
|
+
access_token: string;
|
|
3
|
+
refresh_token: string;
|
|
4
|
+
id_token: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const mockloginSuccessGitlab: {
|
|
7
|
+
access_token: string;
|
|
8
|
+
refresh_token: string;
|
|
9
|
+
id_token: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const mockloginFailed: {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCurrentUrlLocation: (url: string, appUrl: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/authentication",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.2.0",
|
|
4
4
|
"description": "GeoWeb authentication library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"i18next": "^25.0.1",
|
|
27
27
|
"react-i18next": "^15.1.1",
|
|
28
28
|
"@mui/material": "^9.0.1",
|
|
29
|
-
"react-router": "^7.15.
|
|
29
|
+
"react-router": "^7.15.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "19",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"dist",
|
|
41
|
+
"!dist/package.json",
|
|
41
42
|
"README.md",
|
|
42
43
|
"package.json"
|
|
43
44
|
]
|