Skip to content

Commit

Permalink
Improve auth provider return type
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed Jan 10, 2025
1 parent a0ad157 commit 68dd847
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface ExternalAuthProvider {

export interface ExternalAuthProviderResult {
headers: NonSerializableRecord<string, string>
expiration: number
expiration?: number | null
}

interface RawClientConfiguration {
Expand Down
15 changes: 8 additions & 7 deletions lib/shared/src/configuration/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
AuthCredentials,
ClientConfiguration,
ExternalAuthCommand,
NonSerializableRecord,
ExternalAuthProviderResult,
TokenSource,
} from '../configuration'
import { logError } from '../logger'
Expand Down Expand Up @@ -101,10 +101,10 @@ async function executeCommand(cmd: ExternalAuthCommand): Promise<string> {
return stdout.trim()
}

async function getExternalProviderAuthHeaders(
async function getExternalProviderAuthResult(
serverEndpoint: string,
clientConfiguration: ClientConfiguration
): Promise<NonSerializableRecord<string, string> | undefined> {
): Promise<ExternalAuthProviderResult | undefined> {
// Check for external auth provider for this endpoint
const externalProvider = clientConfiguration.authExternalProviders.find(
provider => normalizeServerEndpointURL(provider.endpoint) === serverEndpoint
Expand All @@ -131,11 +131,12 @@ export async function resolveAuth(
return { credentials: { token: clientConfiguration.overrideAuthToken }, serverEndpoint }
}

const authHeaders = await getExternalProviderAuthHeaders(serverEndpoint, clientConfiguration).catch(
error => {
const authHeaders = await getExternalProviderAuthResult(serverEndpoint, clientConfiguration)
.catch(error => {
throw new Error(`Failed to execute external auth command: ${error}`)
}
)
})
.then(result => result?.headers)

if (authHeaders) {
return { credentials: { headers: authHeaders }, serverEndpoint }
}
Expand Down

0 comments on commit 68dd847

Please sign in to comment.