@@ -23,14 +23,14 @@ import {FC, useEffect, useRef} from 'react';
2323 */
2424export interface BaseCallbackProps {
2525 /**
26- * Function to navigate to a different path
26+ * Callback function called when an error occurs
2727 */
28- onNavigate : ( path : string ) => void ;
28+ onError ? : ( error : Error ) => void ;
2929
3030 /**
31- * Callback function called when an error occurs
31+ * Function to navigate to a different path
3232 */
33- onError ? : ( error : Error ) => void ;
33+ onNavigate : ( path : string ) => void ;
3434}
3535
3636/**
@@ -49,12 +49,9 @@ export interface BaseCallbackProps {
4949 * - Handling the assertion and auth/callback POST
5050 * - Managing the authenticated session
5151 */
52- export const BaseCallback : FC < BaseCallbackProps > = ( {
53- onNavigate,
54- onError,
55- } ) => {
52+ export const BaseCallback : FC < BaseCallbackProps > = ( { onNavigate, onError} : BaseCallbackProps ) => {
5653 // Prevent double execution in React Strict Mode
57- const processingRef = useRef ( false ) ;
54+ const processingRef : any = useRef ( false ) ;
5855
5956 useEffect ( ( ) => {
6057 const processOAuthCallback = ( ) : void => {
@@ -65,31 +62,31 @@ export const BaseCallback: FC<BaseCallbackProps> = ({
6562 processingRef . current = true ;
6663
6764 // Declare variables outside try block for use in catch
68- var returnPath = '/' ;
65+ let returnPath : string = '/' ;
6966
7067 try {
71- // Extract OAuth parameters from URL
72- const urlParams = new URLSearchParams ( window . location . search ) ;
73- const code = urlParams . get ( 'code' ) ;
74- const state = urlParams . get ( 'state' ) ;
75- const nonce = urlParams . get ( 'nonce' ) ;
76- const oauthError = urlParams . get ( 'error' ) ;
77- const errorDescription = urlParams . get ( 'error_description' ) ;
78-
79- // Validate and retrieve OAuth state from sessionStorage
68+ // 1. Extract OAuth parameters from URL
69+ const urlParams : URLSearchParams = new URLSearchParams ( window . location . search ) ;
70+ const code : string | null = urlParams . get ( 'code' ) ;
71+ const state : string | null = urlParams . get ( 'state' ) ;
72+ const nonce : string | null = urlParams . get ( 'nonce' ) ;
73+ const oauthError : string | null = urlParams . get ( 'error' ) ;
74+ const errorDescription : string | null = urlParams . get ( 'error_description' ) ;
75+
76+ // 2. Validate and retrieve OAuth state from sessionStorage
8077 if ( ! state ) {
8178 throw new Error ( 'Missing OAuth state parameter - possible security issue' ) ;
8279 }
8380
84- const storedData = sessionStorage . getItem ( `asgardeo_oauth_${ state } ` ) ;
81+ const storedData : string | null = sessionStorage . getItem ( `asgardeo_oauth_${ state } ` ) ;
8582 if ( ! storedData ) {
8683 // If state not found, might be an error callback - try to handle gracefully
8784 if ( oauthError ) {
88- const errorMsg = errorDescription || oauthError || 'OAuth authentication failed' ;
89- const err = new Error ( errorMsg ) ;
85+ const errorMsg : string = errorDescription || oauthError || 'OAuth authentication failed' ;
86+ const err : Error = new Error ( errorMsg ) ;
9087 onError ?.( err ) ;
9188
92- const params = new URLSearchParams ( ) ;
89+ const params : URLSearchParams = new URLSearchParams ( ) ;
9390 params . set ( 'error' , oauthError ) ;
9491 if ( errorDescription ) {
9592 params . set ( 'error_description' , errorDescription ) ;
@@ -104,23 +101,23 @@ export const BaseCallback: FC<BaseCallbackProps> = ({
104101 const { path, timestamp} = JSON . parse ( storedData ) ;
105102 returnPath = path || '/' ;
106103
107- // Validate state freshness
108- const MAX_STATE_AGE = 600000 ; // 10 minutes
104+ // 3. Validate state freshness
105+ const MAX_STATE_AGE : number = 600000 ; // 10 minutes
109106 if ( Date . now ( ) - timestamp > MAX_STATE_AGE ) {
110107 sessionStorage . removeItem ( `asgardeo_oauth_${ state } ` ) ;
111108 throw new Error ( 'OAuth state expired - please try again' ) ;
112109 }
113110
114- // Clean up state
111+ // 4. Clean up state
115112 sessionStorage . removeItem ( `asgardeo_oauth_${ state } ` ) ;
116113
117- // Handle OAuth error response
114+ // 5. Handle OAuth error response
118115 if ( oauthError ) {
119- const errorMsg = errorDescription || oauthError || 'OAuth authentication failed' ;
120- const err = new Error ( errorMsg ) ;
116+ const errorMsg : string = errorDescription || oauthError || 'OAuth authentication failed' ;
117+ const err : Error = new Error ( errorMsg ) ;
121118 onError ?.( err ) ;
122119
123- const params = new URLSearchParams ( ) ;
120+ const params : URLSearchParams = new URLSearchParams ( ) ;
124121 params . set ( 'error' , oauthError ) ;
125122 if ( errorDescription ) {
126123 params . set ( 'error_description' , errorDescription ) ;
@@ -130,28 +127,29 @@ export const BaseCallback: FC<BaseCallbackProps> = ({
130127 return ;
131128 }
132129
133- // Validate required parameters
130+ // 6. Validate required parameters
134131 if ( ! code ) {
135132 throw new Error ( 'Missing OAuth authorization code' ) ;
136133 }
137134
138- // Forward OAuth code to original component
135+ // 7. Forward OAuth code to original component
139136 // The component (SignIn/AcceptInvite) will retrieve flowId/authId from sessionStorage
140- const params = new URLSearchParams ( ) ;
137+ const params : URLSearchParams = new URLSearchParams ( ) ;
141138 params . set ( 'code' , code ) ;
142139 if ( nonce ) {
143140 params . set ( 'nonce' , nonce ) ;
144141 }
145142
146143 onNavigate ( `${ returnPath } ?${ params . toString ( ) } ` ) ;
147144 } catch ( err ) {
148- const errorMessage = err instanceof Error ? err . message : 'OAuth callback processing failed' ;
145+ const errorMessage : string = err instanceof Error ? err . message : 'OAuth callback processing failed' ;
146+ // eslint-disable-next-line no-console
149147 console . error ( 'OAuth callback error:' , err ) ;
150148
151149 onError ?.( err instanceof Error ? err : new Error ( errorMessage ) ) ;
152150
153151 // Redirect back with OAuth error format
154- const params = new URLSearchParams ( ) ;
152+ const params : URLSearchParams = new URLSearchParams ( ) ;
155153 params . set ( 'error' , 'callback_error' ) ;
156154 params . set ( 'error_description' , errorMessage ) ;
157155
0 commit comments