@@ -79,22 +79,57 @@ export class OAuth2ClientWithConfig extends OAuth2Client {
7979 try {
8080 const response = await fetch ( wellKnownUrl )
8181
82+ console . log (
83+ `OAuth2ClientWithConfig: Response status: ${ response . status } ${ response . statusText } `
84+ )
85+ console . log (
86+ `OAuth2ClientWithConfig: Response headers:` ,
87+ Object . fromEntries ( response . headers . entries ( ) )
88+ )
89+
8290 if ( ! response . ok ) {
91+ const errorBody = await response . text ( )
92+ console . error ( `OAuth2ClientWithConfig: Error response body:` , errorBody )
8393 throw new Error (
84- `Failed to fetch OIDC configuration for ${ this . provider } : ${ response . status } ${ response . statusText } `
94+ `Failed to fetch OIDC configuration for ${ this . provider } : ${ response . status } ${ response . statusText } - ${ errorBody } `
8595 )
8696 }
8797
88- const config = ( await response . json ( ) ) as OIDCConfiguration
98+ const responseText = await response . text ( )
99+ console . log (
100+ `OAuth2ClientWithConfig: Raw response body (first 500 chars):` ,
101+ responseText . substring ( 0 , 500 )
102+ )
103+
104+ let config : OIDCConfiguration
105+ try {
106+ config = JSON . parse ( responseText ) as OIDCConfiguration
107+ console . log ( `OAuth2ClientWithConfig: Parsed config keys:` , Object . keys ( config ) )
108+ console . log ( `OAuth2ClientWithConfig: Full parsed config:` , JSON . stringify ( config , null , 2 ) )
109+ } catch ( parseError ) {
110+ console . error ( `OAuth2ClientWithConfig: JSON parse error:` , parseError )
111+ console . error ( `OAuth2ClientWithConfig: Failed to parse response as JSON` )
112+ throw new Error ( `Invalid JSON response from ${ this . provider } : ${ parseError } ` )
113+ }
114+
115+ // Validate required endpoints with detailed logging
116+ console . log ( `OAuth2ClientWithConfig: Validating required endpoints...` )
117+ console . log ( ` - authorization_endpoint: ${ config . authorization_endpoint || 'MISSING' } ` )
118+ console . log ( ` - token_endpoint: ${ config . token_endpoint || 'MISSING' } ` )
119+ console . log ( ` - userinfo_endpoint: ${ config . userinfo_endpoint || 'MISSING' } ` )
89120
90- // Validate required endpoints
91121 if ( ! config . authorization_endpoint ) {
122+ console . error ( `OAuth2ClientWithConfig: authorization_endpoint is missing or undefined` )
123+ console . error ( `OAuth2ClientWithConfig: Config object type:` , typeof config )
124+ console . error ( `OAuth2ClientWithConfig: Config object:` , config )
92125 throw new Error ( `OIDC configuration for ${ this . provider } missing authorization_endpoint` )
93126 }
94127 if ( ! config . token_endpoint ) {
128+ console . error ( `OAuth2ClientWithConfig: token_endpoint is missing or undefined` )
95129 throw new Error ( `OIDC configuration for ${ this . provider } missing token_endpoint` )
96130 }
97131 if ( ! config . userinfo_endpoint ) {
132+ console . error ( `OAuth2ClientWithConfig: userinfo_endpoint is missing or undefined` )
98133 throw new Error ( `OIDC configuration for ${ this . provider } missing userinfo_endpoint` )
99134 }
100135
@@ -112,6 +147,10 @@ export class OAuth2ClientWithConfig extends OAuth2Client {
112147 }
113148 } catch ( error ) {
114149 console . error ( `OAuth2ClientWithConfig: Failed to initialize ${ this . provider } :` , error )
150+ console . error (
151+ `OAuth2ClientWithConfig: Error stack:` ,
152+ error instanceof Error ? error . stack : 'N/A'
153+ )
115154 throw error
116155 }
117156 }
0 commit comments