@asgardeo/auth-react 5.1.1 → 5.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/LICENSE +201 -0
- package/dist/main.js +1 -1
- package/dist/types/src/actions.d.ts.map +1 -0
- package/dist/types/src/api.d.ts.map +1 -0
- package/dist/types/src/authenticate.d.ts.map +1 -0
- package/dist/types/src/authenticated-component.d.ts.map +1 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/models.d.ts.map +1 -0
- package/dist/types/src/public-api.d.ts.map +1 -0
- package/dist/types/src/reducer.d.ts.map +1 -0
- package/dist/types/src/secure-app.d.ts.map +1 -0
- package/package.json +9 -2
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -166
- package/babel.config.js +0 -43
- package/dist/src/actions.d.ts.map +0 -1
- package/dist/src/api.d.ts.map +0 -1
- package/dist/src/authenticate.d.ts.map +0 -1
- package/dist/src/authenticated-component.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/models.d.ts.map +0 -1
- package/dist/src/public-api.d.ts.map +0 -1
- package/dist/src/reducer.d.ts.map +0 -1
- package/dist/src/secure-app.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/actions.ts +0 -51
- package/src/api.ts +0 -466
- package/src/authenticate.tsx +0 -325
- package/src/authenticated-component.tsx +0 -43
- package/src/index.ts +0 -23
- package/src/models.ts +0 -138
- package/src/public-api.ts +0 -22
- package/src/reducer.ts +0 -68
- package/src/secure-app.tsx +0 -83
- package/tsconfig.json +0 -26
- package/webpack.config.js +0 -94
- /package/dist/{src → types/src}/actions.d.ts +0 -0
- /package/dist/{src → types/src}/api.d.ts +0 -0
- /package/dist/{src → types/src}/authenticate.d.ts +0 -0
- /package/dist/{src → types/src}/authenticated-component.d.ts +0 -0
- /package/dist/{src → types/src}/index.d.ts +0 -0
- /package/dist/{src → types/src}/models.d.ts +0 -0
- /package/dist/{src → types/src}/public-api.d.ts +0 -0
- /package/dist/{src → types/src}/reducer.d.ts +0 -0
- /package/dist/{src → types/src}/secure-app.d.ts +0 -0
package/src/authenticate.tsx
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
-
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
-
* in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing,
|
|
12
|
-
* software distributed under the License is distributed on an
|
|
13
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
* KIND, either express or implied. See the License for the
|
|
15
|
-
* specific language governing permissions and limitations
|
|
16
|
-
* under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
AsgardeoAuthException,
|
|
21
|
-
AsgardeoSPAClient,
|
|
22
|
-
AuthClientConfig,
|
|
23
|
-
BasicUserInfo,
|
|
24
|
-
FetchResponse,
|
|
25
|
-
Hooks,
|
|
26
|
-
HttpRequestConfig,
|
|
27
|
-
SPAUtils,
|
|
28
|
-
SignInConfig
|
|
29
|
-
} from "@asgardeo/auth-spa";
|
|
30
|
-
import { SPACustomGrantConfig } from "@asgardeo/auth-spa/src/models/request-custom-grant";
|
|
31
|
-
import React, {
|
|
32
|
-
FunctionComponent,
|
|
33
|
-
MutableRefObject,
|
|
34
|
-
PropsWithChildren,
|
|
35
|
-
ReactNode,
|
|
36
|
-
createContext,
|
|
37
|
-
useContext,
|
|
38
|
-
useEffect,
|
|
39
|
-
useMemo,
|
|
40
|
-
useRef,
|
|
41
|
-
useState
|
|
42
|
-
} from "react";
|
|
43
|
-
import { AuthParams, ReactConfig } from ".";
|
|
44
|
-
import AuthAPI from "./api";
|
|
45
|
-
import { AuthContextInterface, AuthReactConfig, AuthStateInterface } from "./models";
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Default `AuthReactConfig` config.
|
|
49
|
-
*/
|
|
50
|
-
const defaultConfig: Partial<ReactConfig> = {
|
|
51
|
-
disableAutoSignIn: true,
|
|
52
|
-
disableTrySignInSilently: true
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Authentication Context to hold global states in react components.
|
|
57
|
-
*/
|
|
58
|
-
const AuthContext = createContext<AuthContextInterface>(null);
|
|
59
|
-
|
|
60
|
-
interface AuthProviderPropsInterface {
|
|
61
|
-
config: AuthReactConfig;
|
|
62
|
-
fallback?: ReactNode;
|
|
63
|
-
getAuthParams?: () => Promise<AuthParams>;
|
|
64
|
-
onSignOut?: () => void;
|
|
65
|
-
plugin?: AsgardeoSPAClient;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterface>> = (
|
|
69
|
-
props: PropsWithChildren<AuthProviderPropsInterface>
|
|
70
|
-
) => {
|
|
71
|
-
const { children, config: passedConfig, fallback, getAuthParams, onSignOut, plugin } = props;
|
|
72
|
-
const AuthClient: AuthAPI = useMemo(() => {
|
|
73
|
-
return new AuthAPI(plugin);
|
|
74
|
-
}, [ plugin ]);
|
|
75
|
-
|
|
76
|
-
const [ state, dispatch ] = useState<AuthStateInterface>(AuthClient.getState());
|
|
77
|
-
const [ initialized, setInitialized ] = useState(false);
|
|
78
|
-
|
|
79
|
-
const config = useMemo(
|
|
80
|
-
(): AuthReactConfig => ({ ...defaultConfig, ...passedConfig }), [ passedConfig ]
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const signIn = async(
|
|
84
|
-
config?: SignInConfig,
|
|
85
|
-
authorizationCode?: string,
|
|
86
|
-
sessionState?: string,
|
|
87
|
-
authState?: string,
|
|
88
|
-
callback?: (response: BasicUserInfo) => void,
|
|
89
|
-
tokenRequestConfig?: {
|
|
90
|
-
params: Record<string, unknown>
|
|
91
|
-
}
|
|
92
|
-
): Promise<BasicUserInfo> => {
|
|
93
|
-
try {
|
|
94
|
-
setError(null);
|
|
95
|
-
return await AuthClient.signIn(
|
|
96
|
-
dispatch,
|
|
97
|
-
state,
|
|
98
|
-
config,
|
|
99
|
-
authorizationCode,
|
|
100
|
-
sessionState,
|
|
101
|
-
authState,
|
|
102
|
-
callback,
|
|
103
|
-
tokenRequestConfig
|
|
104
|
-
);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
return Promise.reject(error);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const signOut = (callback?: (response: boolean) => void): Promise<boolean> => {
|
|
110
|
-
return AuthClient.signOut(dispatch, state, callback);
|
|
111
|
-
};
|
|
112
|
-
const getBasicUserInfo = () => AuthClient.getBasicUserInfo();
|
|
113
|
-
const httpRequest = (config: HttpRequestConfig) => AuthClient.httpRequest(config);
|
|
114
|
-
const httpRequestAll = (configs: HttpRequestConfig[]) => AuthClient.httpRequestAll(configs);
|
|
115
|
-
const requestCustomGrant = (
|
|
116
|
-
config: SPACustomGrantConfig,
|
|
117
|
-
callback?: (response: BasicUserInfo | FetchResponse<any>) => void
|
|
118
|
-
) => AuthClient.requestCustomGrant(config, callback, dispatch);
|
|
119
|
-
const revokeAccessToken = () => AuthClient.revokeAccessToken(dispatch);
|
|
120
|
-
const getOIDCServiceEndpoints = () => AuthClient.getOIDCServiceEndpoints();
|
|
121
|
-
const getHttpClient = () => AuthClient.getHttpClient();
|
|
122
|
-
const getDecodedIDPIDToken = () => AuthClient.getDecodedIDPIDToken();
|
|
123
|
-
const getDecodedIDToken = () => AuthClient.getDecodedIDToken();
|
|
124
|
-
const getAccessToken = () => AuthClient.getAccessToken();
|
|
125
|
-
const refreshAccessToken = () => AuthClient.refreshAccessToken();
|
|
126
|
-
const isAuthenticated = () => AuthClient.isAuthenticated();
|
|
127
|
-
const enableHttpHandler = () => AuthClient.enableHttpHandler();
|
|
128
|
-
const disableHttpHandler = () => AuthClient.disableHttpHandler();
|
|
129
|
-
const getIDToken = () => AuthClient.getIDToken();
|
|
130
|
-
const updateConfig = (config: Partial<AuthClientConfig<AuthReactConfig>>) => AuthClient.updateConfig(config);
|
|
131
|
-
const on = (hook: Hooks, callback: (response?: any) => void, id?: string): Promise<void> => {
|
|
132
|
-
if (hook === Hooks.CustomGrant) {
|
|
133
|
-
return AuthClient.on(hook, callback, id);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return AuthClient.on(hook, callback);
|
|
137
|
-
};
|
|
138
|
-
const trySignInSilently = (
|
|
139
|
-
additionalParams?: Record<string, string | boolean>,
|
|
140
|
-
tokenRequestConfig?: { params: Record<string, unknown> }
|
|
141
|
-
) => AuthClient.trySignInSilently(state, dispatch, additionalParams, tokenRequestConfig);
|
|
142
|
-
|
|
143
|
-
const [ error, setError ] = useState<AsgardeoAuthException>();
|
|
144
|
-
const reRenderCheckRef: MutableRefObject<boolean> = useRef(false);
|
|
145
|
-
|
|
146
|
-
useEffect(() => {
|
|
147
|
-
if (state.isAuthenticated) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
(async () => {
|
|
151
|
-
setInitialized(await AuthClient.init(config));
|
|
152
|
-
checkIsAuthenticated();
|
|
153
|
-
})();
|
|
154
|
-
|
|
155
|
-
}, [ config ]);
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Try signing in when the component is mounted.
|
|
159
|
-
*/
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
// React 18.x Strict.Mode has a new check for `Ensuring reusable state` to facilitate an upcoming react feature.
|
|
162
|
-
// https://reactjs.org/docs/strict-mode.html#ensuring-reusable-state
|
|
163
|
-
// This will remount all the useEffects to ensure that there are no unexpected side effects.
|
|
164
|
-
// When react remounts the signIn hook of the AuthProvider, it will cause a race condition. Hence, we have to
|
|
165
|
-
// prevent the re-render of this hook as suggested in the following discussion.
|
|
166
|
-
// https://github.com/reactwg/react-18/discussions/18#discussioncomment-795623
|
|
167
|
-
if (reRenderCheckRef.current) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
reRenderCheckRef.current = true;
|
|
172
|
-
|
|
173
|
-
(async () => {
|
|
174
|
-
let isSignedOut: boolean = false;
|
|
175
|
-
// If the component was mounted after the user was redirected to the application upon a successful logout,
|
|
176
|
-
// then the locally stored user session will be cleared as a side effect of registering this sign-out hook.
|
|
177
|
-
await on(Hooks.SignOut, () => {
|
|
178
|
-
isSignedOut = true;
|
|
179
|
-
|
|
180
|
-
if (onSignOut) {
|
|
181
|
-
onSignOut();
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// User is already authenticated. Skip...
|
|
186
|
-
if (state.isAuthenticated) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// If `skipRedirectCallback` is not true, check if the URL has `code` and `session_state` params.
|
|
191
|
-
// If so, initiate the sign in.
|
|
192
|
-
if (!config.skipRedirectCallback) {
|
|
193
|
-
let authParams: AuthParams = null;
|
|
194
|
-
if (getAuthParams && typeof getAuthParams === "function") {
|
|
195
|
-
authParams = await getAuthParams();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const url = new URL(location.href);
|
|
199
|
-
|
|
200
|
-
if ((SPAUtils.hasAuthSearchParamsInURL()
|
|
201
|
-
&& new URL(url.origin + url.pathname).toString() === new URL(config?.signInRedirectURL).toString())
|
|
202
|
-
|| authParams?.authorizationCode
|
|
203
|
-
|| url.searchParams.get("error") )
|
|
204
|
-
{
|
|
205
|
-
try{
|
|
206
|
-
await signIn(
|
|
207
|
-
{ callOnlyOnRedirect: true },
|
|
208
|
-
authParams?.authorizationCode,
|
|
209
|
-
authParams?.sessionState,
|
|
210
|
-
authParams?.state
|
|
211
|
-
);
|
|
212
|
-
setError(null);
|
|
213
|
-
} catch(error) {
|
|
214
|
-
if(error && Object.prototype.hasOwnProperty.call(error, "code")) {
|
|
215
|
-
setError(error);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (AuthClient.getState().isAuthenticated) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (!config.disableAutoSignIn && await AuthClient.isSessionActive()) {
|
|
226
|
-
signIn();
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (config.disableTrySignInSilently || isSignedOut) {
|
|
230
|
-
dispatch({ ...state, isLoading: false });
|
|
231
|
-
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// This uses the RP iframe to get the session. Hence, will not work if 3rd party cookies are disabled.
|
|
236
|
-
// If the browser has these cookies disabled, we'll not be able to retrieve the session on refreshes.
|
|
237
|
-
await trySignInSilently()
|
|
238
|
-
.then(() => {
|
|
239
|
-
// TODO: Add logs when a logger is available.
|
|
240
|
-
// Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
|
|
241
|
-
setError(null);
|
|
242
|
-
})
|
|
243
|
-
.catch((error) => {
|
|
244
|
-
// TODO: Add logs when a logger is available.
|
|
245
|
-
// Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
|
|
246
|
-
if(error && Object.prototype.hasOwnProperty.call(error, "code")) {
|
|
247
|
-
setError(error);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
})();
|
|
251
|
-
|
|
252
|
-
}, [ config ]);
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Check if the user is authenticated and update the state.isAuthenticated value.
|
|
256
|
-
*/
|
|
257
|
-
const checkIsAuthenticated = async () => {
|
|
258
|
-
const isAuthenticatedState = await AuthClient.isAuthenticated();
|
|
259
|
-
|
|
260
|
-
if (isAuthenticatedState) {
|
|
261
|
-
const response = await AuthClient.getBasicUserInfo();
|
|
262
|
-
|
|
263
|
-
if (response) {
|
|
264
|
-
const stateToUpdate ={
|
|
265
|
-
allowedScopes: response.allowedScopes,
|
|
266
|
-
displayName: response.displayName,
|
|
267
|
-
email: response.email,
|
|
268
|
-
isAuthenticated: true,
|
|
269
|
-
isLoading: false,
|
|
270
|
-
isSigningOut: false,
|
|
271
|
-
sub: response.sub,
|
|
272
|
-
username: response.username
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
AuthClient.updateState(stateToUpdate);
|
|
276
|
-
dispatch({ ...state, ...stateToUpdate });
|
|
277
|
-
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
AuthClient.updateState({ ...state, isAuthenticated: isAuthenticatedState, isLoading: false });
|
|
282
|
-
dispatch({ ...state, isAuthenticated: isAuthenticatedState, isLoading: false });
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Render state and special case actions
|
|
288
|
-
*/
|
|
289
|
-
return (
|
|
290
|
-
<AuthContext.Provider
|
|
291
|
-
value={ {
|
|
292
|
-
disableHttpHandler,
|
|
293
|
-
enableHttpHandler,
|
|
294
|
-
getAccessToken,
|
|
295
|
-
getBasicUserInfo,
|
|
296
|
-
getDecodedIDPIDToken,
|
|
297
|
-
getDecodedIDToken,
|
|
298
|
-
getHttpClient,
|
|
299
|
-
getIDToken,
|
|
300
|
-
getOIDCServiceEndpoints,
|
|
301
|
-
httpRequest,
|
|
302
|
-
httpRequestAll,
|
|
303
|
-
isAuthenticated,
|
|
304
|
-
on,
|
|
305
|
-
refreshAccessToken,
|
|
306
|
-
requestCustomGrant,
|
|
307
|
-
revokeAccessToken,
|
|
308
|
-
signIn,
|
|
309
|
-
signOut,
|
|
310
|
-
state,
|
|
311
|
-
trySignInSilently,
|
|
312
|
-
updateConfig,
|
|
313
|
-
error
|
|
314
|
-
} }
|
|
315
|
-
>
|
|
316
|
-
{ initialized ? children : fallback ?? null }
|
|
317
|
-
</AuthContext.Provider>
|
|
318
|
-
);
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
const useAuthContext = (): AuthContextInterface => {
|
|
322
|
-
return useContext(AuthContext);
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
export { AuthProvider, useAuthContext };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
-
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
-
* in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing,
|
|
12
|
-
* software distributed under the License is distributed on an
|
|
13
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
* KIND, either express or implied. See the License for the
|
|
15
|
-
* specific language governing permissions and limitations
|
|
16
|
-
* under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import React, { FunctionComponent, PropsWithChildren, ReactNode } from "react";
|
|
20
|
-
import { useAuthContext } from "./authenticate";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Prop types of the Authenticated component.
|
|
24
|
-
*/
|
|
25
|
-
interface AuthenticatedComponentPropsInterface {
|
|
26
|
-
fallback: ReactNode;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* This component shows the child component only if the user is authenticated. Otherwise, it shows the placeholder.
|
|
31
|
-
*
|
|
32
|
-
* @param {AuthenticatedComponentPropsInterface} props The props of the component
|
|
33
|
-
* @returns {ReactElement} The authenticated component.
|
|
34
|
-
*/
|
|
35
|
-
export const AuthenticatedComponent: FunctionComponent<PropsWithChildren<AuthenticatedComponentPropsInterface>> = (
|
|
36
|
-
props: PropsWithChildren<AuthenticatedComponentPropsInterface>
|
|
37
|
-
) => {
|
|
38
|
-
|
|
39
|
-
const { fallback, children } = props;
|
|
40
|
-
const { state: { isAuthenticated } } = useAuthContext();
|
|
41
|
-
|
|
42
|
-
return <> { isAuthenticated ? children : fallback ?? null } </>;
|
|
43
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
-
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
-
* in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing,
|
|
12
|
-
* software distributed under the License is distributed on an
|
|
13
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
* KIND, either express or implied. See the License for the
|
|
15
|
-
* specific language governing permissions and limitations
|
|
16
|
-
* under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import "core-js";
|
|
20
|
-
import "regenerator-runtime/runtime";
|
|
21
|
-
|
|
22
|
-
export * from "@asgardeo/auth-spa";
|
|
23
|
-
export * from "./public-api";
|
package/src/models.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
-
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
-
* in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing,
|
|
12
|
-
* software distributed under the License is distributed on an
|
|
13
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
* KIND, either express or implied. See the License for the
|
|
15
|
-
* specific language governing permissions and limitations
|
|
16
|
-
* under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
AsgardeoAuthException,
|
|
21
|
-
AuthClientConfig,
|
|
22
|
-
AuthSPAClientConfig,
|
|
23
|
-
BasicUserInfo,
|
|
24
|
-
Config,
|
|
25
|
-
CustomGrantConfig,
|
|
26
|
-
DecodedIDTokenPayload,
|
|
27
|
-
FetchResponse,
|
|
28
|
-
Hooks,
|
|
29
|
-
HttpClientInstance,
|
|
30
|
-
HttpRequestConfig,
|
|
31
|
-
HttpResponse,
|
|
32
|
-
OIDCEndpoints,
|
|
33
|
-
SignInConfig
|
|
34
|
-
} from "@asgardeo/auth-spa";
|
|
35
|
-
|
|
36
|
-
export interface ReactConfig {
|
|
37
|
-
/**
|
|
38
|
-
* The SDK's `AuthProvider` by default is listening to the URL changes to see
|
|
39
|
-
* if `code` & `session_state` search params are available so that it could perform
|
|
40
|
-
* token exchange. This option could be used to override that behaviour.
|
|
41
|
-
*/
|
|
42
|
-
skipRedirectCallback?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* The `AuthProvider`, by default, looks for an active session in the server and updates the session information
|
|
45
|
-
* with the latest session information from the server. This option could be used to disable that behaviour.
|
|
46
|
-
*/
|
|
47
|
-
disableTrySignInSilently?: boolean;
|
|
48
|
-
disableAutoSignIn?: boolean;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type AuthReactConfig = AuthSPAClientConfig & ReactConfig;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Interface for the Authenticated state of the user which is exposed
|
|
55
|
-
* via `state` object from `useAuthContext` hook.
|
|
56
|
-
*/
|
|
57
|
-
export interface AuthStateInterface {
|
|
58
|
-
/**
|
|
59
|
-
* The scopes that are allowed for the user.
|
|
60
|
-
*/
|
|
61
|
-
allowedScopes: string;
|
|
62
|
-
/**
|
|
63
|
-
* The display name of the user.
|
|
64
|
-
*/
|
|
65
|
-
displayName?: string;
|
|
66
|
-
/**
|
|
67
|
-
* The email address of the user.
|
|
68
|
-
*/
|
|
69
|
-
email?: string;
|
|
70
|
-
/**
|
|
71
|
-
* Specifies if the user is authenticated or not.
|
|
72
|
-
*/
|
|
73
|
-
isAuthenticated: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Are the Auth requests loading.
|
|
76
|
-
*/
|
|
77
|
-
isLoading: boolean;
|
|
78
|
-
/**
|
|
79
|
-
* The uid corresponding to the user who the ID token belonged to.
|
|
80
|
-
*/
|
|
81
|
-
sub?: string;
|
|
82
|
-
/**
|
|
83
|
-
* The username of the user.
|
|
84
|
-
*/
|
|
85
|
-
username?: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface AuthContextInterface {
|
|
89
|
-
signIn: (
|
|
90
|
-
config?: SignInConfig,
|
|
91
|
-
authorizationCode?: string,
|
|
92
|
-
sessionState?: string,
|
|
93
|
-
state?: string,
|
|
94
|
-
callback?: (response: BasicUserInfo) => void,
|
|
95
|
-
tokenRequestConfig?: {
|
|
96
|
-
params: Record<string, unknown>
|
|
97
|
-
}
|
|
98
|
-
) => Promise<BasicUserInfo>;
|
|
99
|
-
signOut: (callback?: (response: boolean) => void) => Promise<boolean>;
|
|
100
|
-
getBasicUserInfo(): Promise<BasicUserInfo>;
|
|
101
|
-
httpRequest(config: HttpRequestConfig): Promise<HttpResponse<any>>;
|
|
102
|
-
httpRequestAll(configs: HttpRequestConfig[]): Promise<HttpResponse<any>[]>;
|
|
103
|
-
requestCustomGrant(
|
|
104
|
-
config: CustomGrantConfig,
|
|
105
|
-
callback?: (response: BasicUserInfo | FetchResponse<any>) => void
|
|
106
|
-
): void;
|
|
107
|
-
revokeAccessToken(): Promise<boolean>;
|
|
108
|
-
getOIDCServiceEndpoints(): Promise<OIDCEndpoints>;
|
|
109
|
-
getHttpClient(): Promise<HttpClientInstance>;
|
|
110
|
-
getDecodedIDPIDToken(): Promise<DecodedIDTokenPayload>;
|
|
111
|
-
getDecodedIDToken(): Promise<DecodedIDTokenPayload>;
|
|
112
|
-
getIDToken(): Promise<string>;
|
|
113
|
-
getAccessToken(): Promise<string>;
|
|
114
|
-
refreshAccessToken(): Promise<BasicUserInfo>;
|
|
115
|
-
isAuthenticated(): Promise<boolean>;
|
|
116
|
-
enableHttpHandler(): Promise<boolean>;
|
|
117
|
-
disableHttpHandler(): Promise<boolean>;
|
|
118
|
-
updateConfig(config: Partial<AuthClientConfig<Config>>): Promise<void>;
|
|
119
|
-
trySignInSilently: (additionalParams?: Record<string, string | boolean>,
|
|
120
|
-
tokenRequestConfig?: { params: Record<string, unknown> }) => Promise<boolean | BasicUserInfo>;
|
|
121
|
-
on(hook: Hooks.CustomGrant, callback: (response?: any) => void, id: string): void;
|
|
122
|
-
on(
|
|
123
|
-
hook: Exclude<Hooks, Hooks.CustomGrant>,
|
|
124
|
-
callback: (response?: any) => void
|
|
125
|
-
): void;
|
|
126
|
-
on(hook: Hooks, callback: (response?: any) => void, id?: string): void;
|
|
127
|
-
state: AuthStateInterface;
|
|
128
|
-
error: AsgardeoAuthException;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* The model of the object returned by the `getAuthParams` prop method of the `AuthProvider`.
|
|
133
|
-
*/
|
|
134
|
-
export interface AuthParams {
|
|
135
|
-
authorizationCode?: string;
|
|
136
|
-
sessionState?: string;
|
|
137
|
-
state?: string;
|
|
138
|
-
}
|
package/src/public-api.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
-
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
-
* in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing,
|
|
12
|
-
* software distributed under the License is distributed on an
|
|
13
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
* KIND, either express or implied. See the License for the
|
|
15
|
-
* specific language governing permissions and limitations
|
|
16
|
-
* under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export * from "./authenticate";
|
|
20
|
-
export * from "./models";
|
|
21
|
-
export * from "./authenticated-component";
|
|
22
|
-
export * from "./secure-app";
|
package/src/reducer.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
5
|
-
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
-
* in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing,
|
|
12
|
-
* software distributed under the License is distributed on an
|
|
13
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
* KIND, either express or implied. See the License for the
|
|
15
|
-
* specific language governing permissions and limitations
|
|
16
|
-
* under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { AuthContextReducerActionTypes } from "./actions";
|
|
20
|
-
import { AuthStateInterface } from "./models";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Initial authenticate state.
|
|
24
|
-
*/
|
|
25
|
-
const authenticateInitialState: AuthStateInterface = {
|
|
26
|
-
allowedScopes: "",
|
|
27
|
-
displayName: "",
|
|
28
|
-
email: "",
|
|
29
|
-
isAuthenticated: false,
|
|
30
|
-
isLoading: true,
|
|
31
|
-
username: "",
|
|
32
|
-
sub: ""
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Reducer to handle the state of authentication related actions.
|
|
37
|
-
*
|
|
38
|
-
* @param state - Previous state
|
|
39
|
-
* @param action - Action type
|
|
40
|
-
* @returns The new state
|
|
41
|
-
*/
|
|
42
|
-
const authenticateReducer = (state, action) => {
|
|
43
|
-
switch (action.type) {
|
|
44
|
-
case AuthContextReducerActionTypes.SET_SIGN_IN:
|
|
45
|
-
return {
|
|
46
|
-
...state,
|
|
47
|
-
allowedScopes: action.payload.allowedScopes,
|
|
48
|
-
displayName: action.payload.displayName,
|
|
49
|
-
email: action.payload.email,
|
|
50
|
-
isAuthenticated: true,
|
|
51
|
-
isLoading: false,
|
|
52
|
-
username: action.payload.username,
|
|
53
|
-
sub: action.payload.sub
|
|
54
|
-
};
|
|
55
|
-
case AuthContextReducerActionTypes.SET_SIGN_OUT:
|
|
56
|
-
return {
|
|
57
|
-
...state,
|
|
58
|
-
authenticateInitialState,
|
|
59
|
-
isLoading: false
|
|
60
|
-
};
|
|
61
|
-
case AuthContextReducerActionTypes.SET_PROFILE_INFO:
|
|
62
|
-
return state;
|
|
63
|
-
default:
|
|
64
|
-
return state;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export { authenticateInitialState, authenticateReducer };
|