@asgardeo/auth-react 0.2.16 → 1.1.1
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/README.md +34 -33
- package/dist/main.js +100 -40
- package/dist/src/api.d.ts +7 -7
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/authenticate.d.ts.map +1 -1
- package/dist/src/models.d.ts +5 -4
- package/dist/src/models.d.ts.map +1 -1
- package/dist/src/secure-app.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +162 -74
- package/package.json +2 -2
- package/src/api.ts +10 -16
- package/src/authenticate.tsx +11 -5
- package/src/models.ts +5 -10
- package/src/secure-app.tsx +1 -1
package/src/api.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
BasicUserInfo,
|
|
23
23
|
Config,
|
|
24
24
|
DecodedIDTokenPayload,
|
|
25
|
+
FetchResponse,
|
|
25
26
|
Hooks,
|
|
26
27
|
HttpClientInstance,
|
|
27
28
|
HttpRequestConfig,
|
|
@@ -79,10 +80,11 @@ class AuthAPI {
|
|
|
79
80
|
config: SignInConfig,
|
|
80
81
|
authorizationCode: string,
|
|
81
82
|
sessionState: string,
|
|
83
|
+
authState?: string,
|
|
82
84
|
callback?: (response: BasicUserInfo) => void
|
|
83
85
|
): Promise<BasicUserInfo> {
|
|
84
86
|
return this._client
|
|
85
|
-
.signIn(config, authorizationCode, sessionState)
|
|
87
|
+
.signIn(config, authorizationCode, sessionState, authState)
|
|
86
88
|
.then(async (response: BasicUserInfo) => {
|
|
87
89
|
if (!response) {
|
|
88
90
|
return;
|
|
@@ -168,7 +170,7 @@ class AuthAPI {
|
|
|
168
170
|
*
|
|
169
171
|
* @param {HttpRequestConfig} config - The config object containing attributes necessary to send a request.
|
|
170
172
|
*
|
|
171
|
-
* @return {Promise<
|
|
173
|
+
* @return {Promise<FetchResponse>} - Returns a Promise that resolves with the response to the request.
|
|
172
174
|
*/
|
|
173
175
|
public async httpRequest(config: HttpRequestConfig): Promise<HttpResponse<any>> {
|
|
174
176
|
return this._client.httpRequest(config);
|
|
@@ -182,7 +184,7 @@ class AuthAPI {
|
|
|
182
184
|
*
|
|
183
185
|
* @param {HttpRequestConfig[]} config - The config object containing attributes necessary to send a request.
|
|
184
186
|
*
|
|
185
|
-
* @return {Promise<
|
|
187
|
+
* @return {Promise<FetchResponse[]>} - Returns a Promise that resolves with the responses to the requests.
|
|
186
188
|
*/
|
|
187
189
|
public async httpRequestAll(configs: HttpRequestConfig[]): Promise<HttpResponse<any>[]> {
|
|
188
190
|
return this._client.httpRequestAll(configs);
|
|
@@ -193,17 +195,17 @@ class AuthAPI {
|
|
|
193
195
|
*
|
|
194
196
|
* @param {CustomGrantRequestParams} config - The request parameters.
|
|
195
197
|
*
|
|
196
|
-
* @return {Promise<
|
|
198
|
+
* @return {Promise<FetchResponse<any> | SignInResponse>} - A Promise that resolves with
|
|
197
199
|
* the value returned by the custom grant request.
|
|
198
200
|
*/
|
|
199
201
|
public requestCustomGrant(
|
|
200
202
|
config: SPACustomGrantConfig,
|
|
201
|
-
callback: (response: BasicUserInfo |
|
|
203
|
+
callback: (response: BasicUserInfo | FetchResponse<any>) => void,
|
|
202
204
|
dispatch: (state: AuthStateInterface) => void
|
|
203
|
-
): Promise<BasicUserInfo |
|
|
205
|
+
): Promise<BasicUserInfo | FetchResponse<any>> {
|
|
204
206
|
return this._client
|
|
205
207
|
.requestCustomGrant(config)
|
|
206
|
-
.then((response: BasicUserInfo |
|
|
208
|
+
.then((response: BasicUserInfo | FetchResponse<any>) => {
|
|
207
209
|
if (!response) {
|
|
208
210
|
return;
|
|
209
211
|
}
|
|
@@ -351,15 +353,7 @@ class AuthAPI {
|
|
|
351
353
|
*/
|
|
352
354
|
public on(hook: Hooks.CustomGrant, callback: (response?: any) => void, id: string): Promise<void>;
|
|
353
355
|
public on(
|
|
354
|
-
hook:
|
|
355
|
-
| Hooks.RevokeAccessToken
|
|
356
|
-
| Hooks.HttpRequestError
|
|
357
|
-
| Hooks.HttpRequestFinish
|
|
358
|
-
| Hooks.HttpRequestStart
|
|
359
|
-
| Hooks.HttpRequestSuccess
|
|
360
|
-
| Hooks.Initialize
|
|
361
|
-
| Hooks.SignIn
|
|
362
|
-
| Hooks.SignOut,
|
|
356
|
+
hook: Exclude<Hooks, Hooks.CustomGrant>,
|
|
363
357
|
callback: (response?: any) => void
|
|
364
358
|
): Promise<void>;
|
|
365
359
|
public on(hook: Hooks, callback: (response?: any) => void, id?: string): Promise<void> {
|
package/src/authenticate.tsx
CHANGED
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
import {
|
|
20
20
|
AuthClientConfig,
|
|
21
21
|
BasicUserInfo,
|
|
22
|
+
FetchResponse,
|
|
22
23
|
Hooks,
|
|
23
24
|
HttpRequestConfig,
|
|
24
|
-
HttpResponse,
|
|
25
25
|
SPAUtils,
|
|
26
26
|
SignInConfig
|
|
27
27
|
} from "@asgardeo/auth-spa";
|
|
@@ -44,7 +44,7 @@ import { AuthContextInterface, AuthReactConfig, AuthStateInterface } from "./mod
|
|
|
44
44
|
* Default `AuthReactConfig` config.
|
|
45
45
|
*/
|
|
46
46
|
const defaultConfig: Partial<ReactConfig> = {
|
|
47
|
-
disableTrySignInSilently:
|
|
47
|
+
disableTrySignInSilently: true
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
const AuthClient = new AuthAPI();
|
|
@@ -77,9 +77,10 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
|
|
|
77
77
|
config?: SignInConfig,
|
|
78
78
|
authorizationCode?: string,
|
|
79
79
|
sessionState?: string,
|
|
80
|
+
authState?: string,
|
|
80
81
|
callback?: (response: BasicUserInfo) => void
|
|
81
82
|
): Promise<BasicUserInfo> => {
|
|
82
|
-
return await AuthClient.signIn(dispatch, state, config, authorizationCode, sessionState, callback);
|
|
83
|
+
return await AuthClient.signIn(dispatch, state, config, authorizationCode, sessionState, authState, callback);
|
|
83
84
|
};
|
|
84
85
|
const signOut = (callback?: (response: boolean) => void): Promise<boolean> => {
|
|
85
86
|
return AuthClient.signOut(dispatch, state, callback);
|
|
@@ -89,7 +90,7 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
|
|
|
89
90
|
const httpRequestAll = (configs: HttpRequestConfig[]) => AuthClient.httpRequestAll(configs);
|
|
90
91
|
const requestCustomGrant = (
|
|
91
92
|
config: SPACustomGrantConfig,
|
|
92
|
-
callback?: (response: BasicUserInfo |
|
|
93
|
+
callback?: (response: BasicUserInfo | FetchResponse<any>) => void
|
|
93
94
|
) => AuthClient.requestCustomGrant(config, callback, dispatch);
|
|
94
95
|
const revokeAccessToken = () => AuthClient.revokeAccessToken(dispatch);
|
|
95
96
|
const getOIDCServiceEndpoints = () => AuthClient.getOIDCServiceEndpoints();
|
|
@@ -155,7 +156,12 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
|
|
|
155
156
|
|| authParams?.authorizationCode
|
|
156
157
|
|| url.searchParams.get("error") )
|
|
157
158
|
{
|
|
158
|
-
await signIn(
|
|
159
|
+
await signIn(
|
|
160
|
+
{ callOnlyOnRedirect: true },
|
|
161
|
+
authParams?.authorizationCode,
|
|
162
|
+
authParams?.sessionState,
|
|
163
|
+
authParams?.state
|
|
164
|
+
)
|
|
159
165
|
.then(() => {
|
|
160
166
|
// TODO: Add logs when a logger is available.
|
|
161
167
|
// Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
|
package/src/models.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
Config,
|
|
24
24
|
CustomGrantConfig,
|
|
25
25
|
DecodedIDTokenPayload,
|
|
26
|
+
FetchResponse,
|
|
26
27
|
Hooks,
|
|
27
28
|
HttpClientInstance,
|
|
28
29
|
HttpRequestConfig,
|
|
@@ -87,6 +88,7 @@ export interface AuthContextInterface {
|
|
|
87
88
|
config?: SignInConfig,
|
|
88
89
|
authorizationCode?: string,
|
|
89
90
|
sessionState?: string,
|
|
91
|
+
state?: string,
|
|
90
92
|
callback?: (response: BasicUserInfo) => void
|
|
91
93
|
) => Promise<BasicUserInfo>;
|
|
92
94
|
signOut: (callback?: (response: boolean) => void) => Promise<boolean>;
|
|
@@ -95,7 +97,7 @@ export interface AuthContextInterface {
|
|
|
95
97
|
httpRequestAll(configs: HttpRequestConfig[]): Promise<HttpResponse<any>[]>;
|
|
96
98
|
requestCustomGrant(
|
|
97
99
|
config: CustomGrantConfig,
|
|
98
|
-
callback?: (response: BasicUserInfo |
|
|
100
|
+
callback?: (response: BasicUserInfo | FetchResponse<any>) => void
|
|
99
101
|
): void;
|
|
100
102
|
revokeAccessToken(): Promise<boolean>;
|
|
101
103
|
getOIDCServiceEndpoints(): Promise<OIDCEndpoints>;
|
|
@@ -111,15 +113,7 @@ export interface AuthContextInterface {
|
|
|
111
113
|
trySignInSilently: () => Promise<boolean | BasicUserInfo>;
|
|
112
114
|
on(hook: Hooks.CustomGrant, callback: (response?: any) => void, id: string): void;
|
|
113
115
|
on(
|
|
114
|
-
hook:
|
|
115
|
-
| Hooks.RevokeAccessToken
|
|
116
|
-
| Hooks.HttpRequestError
|
|
117
|
-
| Hooks.HttpRequestFinish
|
|
118
|
-
| Hooks.HttpRequestStart
|
|
119
|
-
| Hooks.HttpRequestSuccess
|
|
120
|
-
| Hooks.Initialize
|
|
121
|
-
| Hooks.SignIn
|
|
122
|
-
| Hooks.SignOut,
|
|
116
|
+
hook: Exclude<Hooks, Hooks.CustomGrant>,
|
|
123
117
|
callback: (response?: any) => void
|
|
124
118
|
): void;
|
|
125
119
|
on(hook: Hooks, callback: (response?: any) => void, id?: string): void;
|
|
@@ -137,4 +131,5 @@ export interface SecureRouteInterface {
|
|
|
137
131
|
export interface AuthParams {
|
|
138
132
|
authorizationCode?: string;
|
|
139
133
|
sessionState?: string;
|
|
134
|
+
state?: string;
|
|
140
135
|
}
|
package/src/secure-app.tsx
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import React, {
|
|
19
|
+
import React, { FunctionComponent, PropsWithChildren, ReactElement, Suspense, useEffect } from "react";
|
|
20
20
|
import { useAuthContext } from "./authenticate";
|
|
21
21
|
import { AuthenticatedComponent } from "./authenticated-component";
|
|
22
22
|
|