Skip to content

Commit e701522

Browse files
committed
Fix TypeScript compilation errors in multi-provider implementation
- Fix OAuth2ClientWithConfig to properly extend arctic OAuth2Client - Rename methods to avoid base class conflicts (exchangeAuthorizationCode, refreshTokens) - Fix OAuth2ProviderManager to use OBPClientService.get() correctly - Fix iteration over Map entries to avoid downlevelIteration issues - Update OAuth2ConnectController with correct method signatures - Fix redirect URI access via getRedirectUri() method
1 parent 0eace07 commit e701522

4 files changed

Lines changed: 40 additions & 28 deletions

File tree

server/controllers/OAuth2CallbackController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class OAuth2CallbackController {
205205

206206
// Exchange code for tokens
207207
console.log(`OAuth2CallbackController: Exchanging authorization code for tokens`)
208-
const tokens = await client.validateAuthorizationCode(code, codeVerifier)
208+
const tokens = await client.exchangeAuthorizationCode(code, codeVerifier)
209209

210210
// Store tokens in session
211211
session.oauth2_access_token = tokens.accessToken

server/controllers/OAuth2ConnectController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ export class OAuth2ConnectController {
169169
session.oauth2_state = state
170170

171171
// Use legacy service to create authorization URL
172-
const authUrl = this.legacyOAuth2Service.createAuthorizationURL(state, codeVerifier, [
172+
const authUrl = this.legacyOAuth2Service.createAuthorizationURL(state, [
173173
'openid',
174174
'profile',
175175
'email'
176176
])
177177

178178
console.log('OAuth2ConnectController: Redirecting to legacy OIDC provider')
179-
return response.redirect(authUrl)
179+
return response.redirect(authUrl.toString())
180180
}
181181

182182
/**
@@ -186,7 +186,7 @@ export class OAuth2ConnectController {
186186
const authEndpoint = client.getAuthorizationEndpoint()
187187
const params = new URLSearchParams({
188188
client_id: client.clientId,
189-
redirect_uri: client.redirectURI,
189+
redirect_uri: client.getRedirectUri(),
190190
response_type: 'code',
191191
scope: 'openid profile email',
192192
state: state,

server/services/OAuth2ClientWithConfig.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*/
2727

28-
import { OAuth2Client } from 'arctic'
28+
import { OAuth2Client, OAuth2Tokens } from 'arctic'
2929
import type { OIDCConfiguration, TokenResponse } from '../types/oauth2.js'
3030

3131
/**
@@ -48,10 +48,14 @@ import type { OIDCConfiguration, TokenResponse } from '../types/oauth2.js'
4848
export class OAuth2ClientWithConfig extends OAuth2Client {
4949
public OIDCConfig?: OIDCConfiguration
5050
public provider: string
51+
private _clientSecret: string
52+
private _redirectUri: string
5153

5254
constructor(clientId: string, clientSecret: string, redirectUri: string, provider: string) {
5355
super(clientId, clientSecret, redirectUri)
5456
this.provider = provider
57+
this._clientSecret = clientSecret
58+
this._redirectUri = redirectUri
5559
}
5660

5761
/**
@@ -158,16 +162,15 @@ export class OAuth2ClientWithConfig extends OAuth2Client {
158162
}
159163

160164
/**
161-
* Validate authorization code and exchange for tokens
165+
* Exchange authorization code for tokens
162166
*
163-
* This method extends the base OAuth2Client functionality to support
164-
* provider-specific token exchange requirements (e.g., Basic Auth vs form-based credentials)
167+
* This method provides a simpler interface for token exchange
165168
*
166169
* @param code - Authorization code from OIDC provider
167170
* @param codeVerifier - PKCE code verifier
168171
* @returns Token response with access token, refresh token, and ID token
169172
*/
170-
async validateAuthorizationCode(code: string, codeVerifier: string): Promise<TokenResponse> {
173+
async exchangeAuthorizationCode(code: string, codeVerifier: string): Promise<TokenResponse> {
171174
const tokenEndpoint = this.getTokenEndpoint()
172175

173176
console.log(`OAuth2ClientWithConfig: Exchanging authorization code for ${this.provider}`)
@@ -176,19 +179,19 @@ export class OAuth2ClientWithConfig extends OAuth2Client {
176179
const body = new URLSearchParams({
177180
grant_type: 'authorization_code',
178181
code: code,
179-
redirect_uri: this.redirectURI,
182+
redirect_uri: this._redirectUri,
180183
code_verifier: codeVerifier,
181184
client_id: this.clientId
182185
})
183186

184187
// Add client_secret to body (some providers prefer this over Basic Auth)
185-
if (this.clientSecret) {
186-
body.append('client_secret', this.clientSecret)
188+
if (this._clientSecret) {
189+
body.append('client_secret', this._clientSecret)
187190
}
188191

189192
try {
190193
// Try with Basic Authentication first (RFC 6749 standard)
191-
const authHeader = Buffer.from(`${this.clientId}:${this.clientSecret}`).toString('base64')
194+
const authHeader = Buffer.from(`${this.clientId}:${this._clientSecret}`).toString('base64')
192195

193196
const response = await fetch(tokenEndpoint, {
194197
method: 'POST',
@@ -229,7 +232,7 @@ export class OAuth2ClientWithConfig extends OAuth2Client {
229232
* @param refreshToken - Refresh token from previous authentication
230233
* @returns New token response
231234
*/
232-
async refreshAccessToken(refreshToken: string): Promise<TokenResponse> {
235+
async refreshTokens(refreshToken: string): Promise<TokenResponse> {
233236
const tokenEndpoint = this.getTokenEndpoint()
234237

235238
console.log(`OAuth2ClientWithConfig: Refreshing access token for ${this.provider}`)
@@ -240,12 +243,12 @@ export class OAuth2ClientWithConfig extends OAuth2Client {
240243
client_id: this.clientId
241244
})
242245

243-
if (this.clientSecret) {
244-
body.append('client_secret', this.clientSecret)
246+
if (this._clientSecret) {
247+
body.append('client_secret', this._clientSecret)
245248
}
246249

247250
try {
248-
const authHeader = Buffer.from(`${this.clientId}:${this.clientSecret}`).toString('base64')
251+
const authHeader = Buffer.from(`${this.clientId}:${this._clientSecret}`).toString('base64')
249252

250253
const response = await fetch(tokenEndpoint, {
251254
method: 'POST',
@@ -279,4 +282,18 @@ export class OAuth2ClientWithConfig extends OAuth2Client {
279282
throw error
280283
}
281284
}
285+
286+
/**
287+
* Get the redirect URI
288+
*/
289+
getRedirectUri(): string {
290+
return this._redirectUri
291+
}
292+
293+
/**
294+
* Get the client secret
295+
*/
296+
getClientSecret(): string {
297+
return this._clientSecret
298+
}
282299
}

server/services/OAuth2ProviderManager.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,15 @@ export class OAuth2ProviderManager {
7777

7878
try {
7979
// Use OBPClientService to call the API
80-
const response = await this.obpClientService.call<WellKnownResponse>(
81-
'GET',
82-
'/obp/v5.1.0/well-known',
83-
null,
84-
null
85-
)
80+
const response = await this.obpClientService.get('/obp/v5.1.0/well-known', null)
8681

8782
if (!response.well_known_uris || response.well_known_uris.length === 0) {
8883
console.warn('OAuth2ProviderManager: No well-known URIs found in OBP API response')
8984
return []
9085
}
9186

9287
console.log(`OAuth2ProviderManager: Found ${response.well_known_uris.length} providers:`)
93-
response.well_known_uris.forEach((uri) => {
88+
response.well_known_uris.forEach((uri: WellKnownUri) => {
9489
console.log(` - ${uri.provider}: ${uri.url}`)
9590
})
9691

@@ -219,9 +214,9 @@ export class OAuth2ProviderManager {
219214

220215
const checkPromises: Promise<void>[] = []
221216

222-
for (const [providerName, client] of this.providers.entries()) {
217+
this.providers.forEach((client, providerName) => {
223218
checkPromises.push(this.checkProviderHealth(providerName, client))
224-
}
219+
})
225220

226221
await Promise.allSettled(checkPromises)
227222
}
@@ -288,11 +283,11 @@ export class OAuth2ProviderManager {
288283
getAvailableProviders(): string[] {
289284
const available: string[] = []
290285

291-
for (const [name, status] of this.providerStatus.entries()) {
286+
this.providerStatus.forEach((status, name) => {
292287
if (status.available && this.providers.has(name)) {
293288
available.push(name)
294289
}
295-
}
290+
})
296291

297292
return available
298293
}

0 commit comments

Comments
 (0)