Skip to content

Commit 32a15c2

Browse files
committed
added console logging regarding auth endpoints
1 parent 7a0c1d9 commit 32a15c2

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

server/services/OAuth2ClientWithConfig.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

server/services/OAuth2ProviderManager.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,38 @@ export class OAuth2ProviderManager {
9494

9595
// Multi-provider mode: fetch from OBP API
9696
console.log('OAuth2ProviderManager: Fetching well-known URIs from OBP API...')
97+
console.log(
98+
`OAuth2ProviderManager: Target URL: ${this.obpClientService.getOBPClientConfig().baseUri}/obp/v5.1.0/well-known`
99+
)
97100

98101
try {
99102
// Use OBPClientService to call the API
100103
const response = await this.obpClientService.get('/obp/v5.1.0/well-known', null)
101104

105+
console.log(
106+
'OAuth2ProviderManager: Raw response from OBP API:',
107+
JSON.stringify(response, null, 2)
108+
)
109+
102110
if (!response.well_known_uris || response.well_known_uris.length === 0) {
103111
console.warn('OAuth2ProviderManager: No well-known URIs found in OBP API response')
112+
console.warn('OAuth2ProviderManager: Response keys:', Object.keys(response))
104113
return []
105114
}
106115

107116
console.log(`OAuth2ProviderManager: Found ${response.well_known_uris.length} providers:`)
108117
response.well_known_uris.forEach((uri: WellKnownUri) => {
109118
console.log(` - ${uri.provider}: ${uri.url}`)
119+
console.log(` Testing accessibility of: ${uri.url}`)
110120
})
111121

112122
return response.well_known_uris
113123
} catch (error) {
114124
console.error('OAuth2ProviderManager: Failed to fetch well-known URIs:', error)
125+
console.error(
126+
'OAuth2ProviderManager: Error details:',
127+
error instanceof Error ? error.message : String(error)
128+
)
115129
console.warn('OAuth2ProviderManager: Falling back to no providers')
116130
return []
117131
}

0 commit comments

Comments
 (0)