Skip to content

Commit fb0b452

Browse files
authored
feat: add 'external_idp' as a sso connection type (#679)
## Problem Flare is very rigid about behavior between 'builderId' and 'identityCenter' ## Solution Expose 'external_idp' as new case <!--- REMINDER: - Read CONTRIBUTING.md first. - Add test coverage for your changes. - Link to related issues/commits. - Testing: how did you test your changes? - Screenshots if applicable --> ## License By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 63d50b3 commit fb0b452

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

runtimes/runtimes/auth/auth.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ describe('Auth', () => {
361361
assert.deepEqual(credentialsProvider.getConnectionType(), 'builderId')
362362
})
363363

364-
it('getConnectionType return identityCenter', async () => {
364+
it('getConnectionType return identityCenter for start url', async () => {
365365
const CONNECTION_METADATA = {
366366
sso: {
367367
startUrl: 'https://idc.awsapps.com/start',
@@ -381,6 +381,46 @@ describe('Auth', () => {
381381
assert.deepEqual(credentialsProvider.getConnectionType(), 'identityCenter')
382382
})
383383

384+
it('getConnectionType return identityCenter for issuer url', async () => {
385+
const CONNECTION_METADATA = {
386+
sso: {
387+
startUrl: 'https://idc.awsapps.com/start',
388+
},
389+
}
390+
391+
const updateRequest: UpdateCredentialsParams = {
392+
data: bearerCredentials,
393+
metadata: CONNECTION_METADATA,
394+
encrypted: false,
395+
}
396+
const auth = new Auth(serverConnection, lspRouter)
397+
const credentialsProvider: CredentialsProvider = auth.getCredentialsProvider()
398+
399+
await clientConnection.sendRequest(credentialsProtocolMethodNames.bearerCredentialsUpdate, updateRequest)
400+
401+
assert.deepEqual(credentialsProvider.getConnectionType(), 'identityCenter')
402+
})
403+
404+
it('getConnectionType return external_idp for non-IdC bearer', async () => {
405+
const CONNECTION_METADATA = {
406+
sso: {
407+
startUrl: 'https://some.nice.example.com',
408+
},
409+
}
410+
411+
const updateRequest: UpdateCredentialsParams = {
412+
data: bearerCredentials,
413+
metadata: CONNECTION_METADATA,
414+
encrypted: false,
415+
}
416+
const auth = new Auth(serverConnection, lspRouter)
417+
const credentialsProvider: CredentialsProvider = auth.getCredentialsProvider()
418+
419+
await clientConnection.sendRequest(credentialsProtocolMethodNames.bearerCredentialsUpdate, updateRequest)
420+
421+
assert.deepEqual(credentialsProvider.getConnectionType(), 'external_idp')
422+
})
423+
384424
it('getConnectionType return none', async () => {
385425
const CONNECTION_METADATA = {
386426
sso: {},

runtimes/runtimes/auth/auth.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,38 @@ export class Auth {
7979
},
8080
getConnectionType: () => {
8181
const startUrl = this.connectionMetadata?.sso?.startUrl
82-
return !startUrl ? 'none' : startUrl.includes(BUILDER_ID_START_URL) ? 'builderId' : 'identityCenter'
82+
if (!startUrl) {
83+
return 'none'
84+
}
85+
86+
if (startUrl.includes(BUILDER_ID_START_URL)) {
87+
return 'builderId'
88+
}
89+
90+
// Issuer format:
91+
// Commercial: https://identitycenter.amazonaws.com/ssoins-...
92+
// GovCloud: https://identitycenter.us-gov.amazonaws.com/ssoins-...
93+
// China: https://identitycenter.amazonaws.com.cn/ssoins-...
94+
95+
// Start URL format:
96+
// Commercial: https://d-12345abcde.awsapps.com/start
97+
// GovCloud: https://start.us-gov-home.awsapps.com/directory/d-12345abcde
98+
// China: https://start.home.awsapps.cn/directory/d-12345abcde
99+
if (!URL.canParse(startUrl)) {
100+
return 'none'
101+
}
102+
const host = new URL(startUrl).host
103+
104+
if (
105+
host.endsWith('.amazonaws.com') ||
106+
host.endsWith('.awsapps.com') ||
107+
host.endsWith('.amazonaws.cn') ||
108+
host.endsWith('.awsapps.cn')
109+
) {
110+
return 'identityCenter'
111+
}
112+
113+
return 'external_idp'
83114
},
84115
onCredentialsDeleted: (handler: (type: CredentialsType) => void) => {
85116
this.credentialsDeleteHandler = handler

runtimes/server-interface/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { IamCredentials, BearerCredentials, ConnectionMetadata }
55

66
export type CredentialsType = 'iam' | 'bearer'
77
export type Credentials = IamCredentials | BearerCredentials
8-
export type SsoConnectionType = 'builderId' | 'identityCenter' | 'none'
8+
export type SsoConnectionType = 'builderId' | 'identityCenter' | 'external_idp' | 'none'
99

1010
export interface CredentialsProvider {
1111
hasCredentials: (type: CredentialsType) => boolean

0 commit comments

Comments
 (0)