@contember/engine-tenant-api 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/model/service/IDPSignInManager.d.ts +1 -0
- package/dist/src/model/service/IDPSignInManager.d.ts.map +1 -1
- package/dist/src/model/service/IDPSignInManager.js +1 -1
- package/dist/src/model/service/IDPSignInManager.js.map +1 -1
- package/dist/src/model/service/idp/IdentityProviderHandler.d.ts +3 -3
- package/dist/src/model/service/idp/IdentityProviderHandler.d.ts.map +1 -1
- package/dist/src/model/service/idp/providers/AppleProvider.d.ts +2 -2
- package/dist/src/model/service/idp/providers/AppleProvider.d.ts.map +1 -1
- package/dist/src/model/service/idp/providers/FacebookProvider.d.ts +2 -2
- package/dist/src/model/service/idp/providers/FacebookProvider.d.ts.map +1 -1
- package/dist/src/model/service/idp/providers/OIDCHelpers.d.ts +2 -2
- package/dist/src/model/service/idp/providers/OIDCHelpers.d.ts.map +1 -1
- package/dist/src/model/service/idp/providers/OIDCHelpers.js +2 -2
- package/dist/src/model/service/idp/providers/OIDCHelpers.js.map +1 -1
- package/dist/src/model/service/idp/providers/OIDCProvider.d.ts +2 -2
- package/dist/src/model/service/idp/providers/OIDCProvider.d.ts.map +1 -1
- package/dist/src/resolvers/mutation/person/IDPMutationResolver.d.ts.map +1 -1
- package/dist/src/resolvers/mutation/person/IDPMutationResolver.js +4 -1
- package/dist/src/resolvers/mutation/person/IDPMutationResolver.js.map +1 -1
- package/dist/src/schema/index.d.ts +2 -0
- package/dist/src/schema/index.d.ts.map +1 -1
- package/dist/src/schema/tenant.graphql.d.ts.map +1 -1
- package/dist/src/schema/tenant.graphql.js +1 -0
- package/dist/src/schema/tenant.graphql.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/src/IdPMock.d.ts +2 -2
- package/dist/tests/src/IdPMock.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/model/service/IDPSignInManager.ts +7 -6
- package/src/model/service/idp/IdentityProviderHandler.ts +3 -3
- package/src/model/service/idp/providers/AppleProvider.ts +2 -2
- package/src/model/service/idp/providers/FacebookProvider.ts +2 -2
- package/src/model/service/idp/providers/OIDCHelpers.ts +4 -4
- package/src/model/service/idp/providers/OIDCProvider.ts +2 -2
- package/src/resolvers/mutation/person/IDPMutationResolver.ts +4 -1
- package/src/schema/index.ts +2 -0
- package/src/schema/tenant.graphql.ts +1 -0
- package/tests/src/IdPMock.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-tenant-api",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"test": "vitest --dir ./tests/cases --no-threads"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@contember/authorization": "1.4.
|
|
17
|
-
"@contember/config-loader": "1.4.
|
|
18
|
-
"@contember/database": "1.4.
|
|
19
|
-
"@contember/database-migrations": "1.4.
|
|
20
|
-
"@contember/dic": "1.4.
|
|
21
|
-
"@contember/graphql-utils": "1.4.
|
|
22
|
-
"@contember/logger": "1.4.
|
|
23
|
-
"@contember/schema": "1.4.
|
|
24
|
-
"@contember/schema-utils": "1.4.
|
|
25
|
-
"@contember/typesafe": "1.4.
|
|
16
|
+
"@contember/authorization": "1.4.3",
|
|
17
|
+
"@contember/config-loader": "1.4.3",
|
|
18
|
+
"@contember/database": "1.4.3",
|
|
19
|
+
"@contember/database-migrations": "1.4.3",
|
|
20
|
+
"@contember/dic": "1.4.3",
|
|
21
|
+
"@contember/graphql-utils": "1.4.3",
|
|
22
|
+
"@contember/logger": "1.4.3",
|
|
23
|
+
"@contember/schema": "1.4.3",
|
|
24
|
+
"@contember/schema-utils": "1.4.3",
|
|
25
|
+
"@contember/typesafe": "1.4.3",
|
|
26
26
|
"@graphql-tools/utils": "^10.0.8",
|
|
27
27
|
"graphql-tag": "^2.12.6",
|
|
28
28
|
"jose": "^5.1.1",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"otpauth": "^9.1.5"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@contember/database-tester": "1.4.
|
|
35
|
+
"@contember/database-tester": "1.4.3",
|
|
36
36
|
"@graphql-codegen/cli": "^5.0.0",
|
|
37
37
|
"@graphql-codegen/typescript": "^4.0.1",
|
|
38
38
|
"@graphql-codegen/typescript-operations": "^4.0.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiKeyManager } from './apiKey'
|
|
2
2
|
import { IdentityProviderBySlugQuery, PersonByIdPQuery, PersonQuery, PersonRow } from '../queries'
|
|
3
|
-
import {
|
|
3
|
+
import { IDPResponse, IDPHandlerRegistry, IDPResponseError, IDPValidationError } from './idp'
|
|
4
4
|
import { Response, ResponseError, ResponseOk } from '../utils/Response'
|
|
5
5
|
import { InitSignInIdpErrorCode, InitSignInIdpResult, SignInIdpErrorCode } from '../../schema'
|
|
6
6
|
import { DatabaseContext } from '../utils'
|
|
@@ -28,7 +28,7 @@ class IDPSignInManager {
|
|
|
28
28
|
}
|
|
29
29
|
const providerService = this.idpRegistry.getHandler(provider.type)
|
|
30
30
|
const validatedConfig = providerService.validateConfiguration(provider.configuration)
|
|
31
|
-
let claim:
|
|
31
|
+
let claim: IDPResponse
|
|
32
32
|
try {
|
|
33
33
|
claim = await providerService.processResponse(
|
|
34
34
|
validatedConfig,
|
|
@@ -54,7 +54,7 @@ class IDPSignInManager {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const sessionToken = await this.apiKeyManager.createSessionApiKey(db, personRow.identity_id, expiration)
|
|
57
|
-
return new ResponseOk({ person: personRow, token: sessionToken })
|
|
57
|
+
return new ResponseOk({ person: personRow, token: sessionToken, idpResponse: claim })
|
|
58
58
|
})
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -84,7 +84,7 @@ class IDPSignInManager {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
private async resolvePerson(db: DatabaseContext, claim:
|
|
87
|
+
private async resolvePerson(db: DatabaseContext, claim: IDPResponse, provider: IdentityProviderRow): Promise<PersonRow | null> {
|
|
88
88
|
const personByIdPQuery = new PersonByIdPQuery(provider.id, claim.externalIdentifier)
|
|
89
89
|
const personByIdp = await db.queryHandler.fetch(personByIdPQuery)
|
|
90
90
|
if (personByIdp) {
|
|
@@ -108,7 +108,7 @@ class IDPSignInManager {
|
|
|
108
108
|
return null
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
private async signUp(db: DatabaseContext, { email, name, externalIdentifier }:
|
|
111
|
+
private async signUp(db: DatabaseContext, { email, name, externalIdentifier }: IDPResponse, provider: IdentityProviderRow): Promise<PersonRow> {
|
|
112
112
|
const roles = [TenantRole.PERSON]
|
|
113
113
|
const identityId = await db.commandBus.execute(new CreateIdentityCommand(roles))
|
|
114
114
|
const newPerson = await db.commandBus.execute(new CreatePersonCommand({
|
|
@@ -125,7 +125,7 @@ class IDPSignInManager {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
private async saveIdpIdentifier(db: DatabaseContext, provider: IdentityProviderRow, claim:
|
|
128
|
+
private async saveIdpIdentifier(db: DatabaseContext, provider: IdentityProviderRow, claim: IDPResponse, person: PersonRow) {
|
|
129
129
|
await db.commandBus.execute(new CreatePersonIdentityProviderIdentifierCommand(provider.id, person.id, claim.externalIdentifier))
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -136,6 +136,7 @@ namespace IDPSignInManager {
|
|
|
136
136
|
interface SignInIDPResult {
|
|
137
137
|
readonly person: PersonRow
|
|
138
138
|
readonly token: string
|
|
139
|
+
readonly idpResponse?: Record<string, unknown>
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
export type SignInIDPResponse = Response<SignInIDPResult, SignInIdpErrorCode>
|
|
@@ -3,17 +3,17 @@ export interface InitIDPAuthResult {
|
|
|
3
3
|
sessionData: unknown
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export type IDPResponse = {
|
|
7
7
|
externalIdentifier: string
|
|
8
8
|
email?: string
|
|
9
9
|
name?: string
|
|
10
|
-
}
|
|
10
|
+
} & Record<string, unknown>
|
|
11
11
|
|
|
12
12
|
export interface IdentityProviderHandler<Configuration extends {}> {
|
|
13
13
|
|
|
14
14
|
initAuth: (configuration: Configuration, data: unknown) => Promise<InitIDPAuthResult>
|
|
15
15
|
|
|
16
|
-
processResponse: (configuration: Configuration, responseData: unknown) => Promise<
|
|
16
|
+
processResponse: (configuration: Configuration, responseData: unknown) => Promise<IDPResponse>
|
|
17
17
|
|
|
18
18
|
validateConfiguration: (config: unknown) => Configuration
|
|
19
19
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Typesafe from '@contember/typesafe'
|
|
2
|
-
import { IdentityProviderHandler,
|
|
2
|
+
import { IdentityProviderHandler, IDPResponse, InitIDPAuthResult } from '../IdentityProviderHandler'
|
|
3
3
|
import { OIDCConfiguration, OIDCConfigurationOptions, OIDCInitData, OIDCResponseData, OIDCSessionData } from './OIDCTypes'
|
|
4
4
|
import { catchTypesafe } from './helpers'
|
|
5
5
|
import { IDPValidationError } from '../IDPValidationError'
|
|
@@ -36,7 +36,7 @@ export class AppleProvider implements IdentityProviderHandler<AppleConfiguration
|
|
|
36
36
|
})
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
public async processResponse(configuration: AppleConfiguration, data: unknown): Promise<
|
|
39
|
+
public async processResponse(configuration: AppleConfiguration, data: unknown): Promise<IDPResponse> {
|
|
40
40
|
const responseData = catchTypesafe(OIDCResponseData, IDPValidationError)(data)
|
|
41
41
|
const client = await this.createOIDCClient(configuration)
|
|
42
42
|
return await handleOIDCResponse(client, responseData)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Typesafe from '@contember/typesafe'
|
|
2
2
|
import { Client, Issuer } from 'openid-client'
|
|
3
|
-
import { IdentityProviderHandler,
|
|
3
|
+
import { IdentityProviderHandler, IDPResponse, InitIDPAuthResult } from '../IdentityProviderHandler'
|
|
4
4
|
import { IDPValidationError } from '../IDPValidationError'
|
|
5
5
|
import { InvalidIDPConfigurationError } from '../InvalidIDPConfigurationError'
|
|
6
6
|
import { catchTypesafe } from './helpers'
|
|
@@ -85,7 +85,7 @@ export class FacebookProvider implements IdentityProviderHandler<FacebookConfigu
|
|
|
85
85
|
})
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
public async processResponse(configuration: FacebookConfiguration, data: unknown): Promise<
|
|
88
|
+
public async processResponse(configuration: FacebookConfiguration, data: unknown): Promise<IDPResponse> {
|
|
89
89
|
const responseData = catchTypesafe(FacebookResponseData, IDPValidationError)(data)
|
|
90
90
|
|
|
91
91
|
if (!('authResponse' in responseData)) {
|
|
@@ -2,7 +2,7 @@ import { Client, custom, errors, generators } from 'openid-client'
|
|
|
2
2
|
import { OIDCResponseData } from './OIDCTypes'
|
|
3
3
|
import { IDPValidationError } from '../IDPValidationError'
|
|
4
4
|
import { IDPResponseError } from '../IDPResponseError'
|
|
5
|
-
import {
|
|
5
|
+
import { IDPResponse, InitIDPAuthResult } from '../IdentityProviderHandler'
|
|
6
6
|
|
|
7
7
|
custom.setHttpOptionsDefaults({
|
|
8
8
|
timeout: 5000,
|
|
@@ -25,7 +25,7 @@ export const initOIDCAuth = async (client: Client, { redirectUrl, claims, respon
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export const handleOIDCResponse = async (client: Client, { sessionData, redirectUrl, ...otherData }: OIDCResponseData): Promise<
|
|
28
|
+
export const handleOIDCResponse = async (client: Client, { sessionData, redirectUrl, ...otherData }: OIDCResponseData): Promise<IDPResponse> => {
|
|
29
29
|
const params = 'parameters' in otherData ? otherData.parameters : client.callbackParams(otherData.url)
|
|
30
30
|
if (params.state && !sessionData?.state) {
|
|
31
31
|
throw new IDPValidationError(`state is present in parameters, but missing in session data`)
|
|
@@ -33,10 +33,10 @@ export const handleOIDCResponse = async (client: Client, { sessionData, redirect
|
|
|
33
33
|
try {
|
|
34
34
|
const result = await client.callback(redirectUrl, params, sessionData)
|
|
35
35
|
const claims = result.claims()
|
|
36
|
+
const { at_hash, c_hash, nonce, ...claimsWithoutHashes } = claims
|
|
36
37
|
return {
|
|
37
38
|
externalIdentifier: claims.sub,
|
|
38
|
-
|
|
39
|
-
name: claims.name,
|
|
39
|
+
...claimsWithoutHashes,
|
|
40
40
|
}
|
|
41
41
|
} catch (e: any) {
|
|
42
42
|
if (e instanceof errors.RPError) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client, Issuer } from 'openid-client'
|
|
2
|
-
import { IdentityProviderHandler,
|
|
2
|
+
import { IdentityProviderHandler, IDPResponse, InitIDPAuthResult } from '../IdentityProviderHandler'
|
|
3
3
|
import { InvalidIDPConfigurationError } from '../InvalidIDPConfigurationError'
|
|
4
4
|
import { catchTypesafe } from './helpers'
|
|
5
5
|
import { OIDCConfiguration, OIDCInitData, OIDCResponseData } from './OIDCTypes'
|
|
@@ -21,7 +21,7 @@ export class OIDCProvider implements IdentityProviderHandler<OIDCConfiguration>
|
|
|
21
21
|
})
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
public async processResponse(configuration: OIDCConfiguration, data: unknown): Promise<
|
|
24
|
+
public async processResponse(configuration: OIDCConfiguration, data: unknown): Promise<IDPResponse> {
|
|
25
25
|
const responseData = catchTypesafe(OIDCResponseData, IDPValidationError)(data)
|
|
26
26
|
const client = await this.createOIDCClient(configuration)
|
|
27
27
|
return await handleOIDCResponse(client, responseData)
|
|
@@ -55,7 +55,10 @@ export class IDPMutationResolver implements MutationResolvers {
|
|
|
55
55
|
return {
|
|
56
56
|
ok: true,
|
|
57
57
|
errors: [],
|
|
58
|
-
result:
|
|
58
|
+
result: {
|
|
59
|
+
...await this.signInResponseFactory.createResponse(signIn.result, context),
|
|
60
|
+
idpResponse: signIn.result.idpResponse,
|
|
61
|
+
},
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
}
|
package/src/schema/index.ts
CHANGED
|
@@ -1138,6 +1138,7 @@ export type SignInIdpResponse = {
|
|
|
1138
1138
|
|
|
1139
1139
|
export type SignInIdpResult = CommonSignInResult & {
|
|
1140
1140
|
readonly __typename?: 'SignInIDPResult'
|
|
1141
|
+
readonly idpResponse?: Maybe<Scalars['Json']['output']>
|
|
1141
1142
|
readonly person: Person
|
|
1142
1143
|
readonly token: Scalars['String']['output']
|
|
1143
1144
|
}
|
|
@@ -2238,6 +2239,7 @@ export type SignInIdpResponseResolvers<ContextType = any, ParentType extends Res
|
|
|
2238
2239
|
}
|
|
2239
2240
|
|
|
2240
2241
|
export type SignInIdpResultResolvers<ContextType = any, ParentType extends ResolversParentTypes['SignInIDPResult'] = ResolversParentTypes['SignInIDPResult']> = {
|
|
2242
|
+
idpResponse?: Resolver<Maybe<ResolversTypes['Json']>, ParentType, ContextType>
|
|
2241
2243
|
person?: Resolver<ResolversTypes['Person'], ParentType, ContextType>
|
|
2242
2244
|
token?: Resolver<ResolversTypes['String'], ParentType, ContextType>
|
|
2243
2245
|
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>
|
package/tests/src/IdPMock.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IdentityProviderHandler,
|
|
1
|
+
import { IdentityProviderHandler, IDPResponse, InitIDPAuthResult } from '../../src'
|
|
2
2
|
|
|
3
3
|
export class IdPMock implements IdentityProviderHandler<any> {
|
|
4
4
|
initAuth(configuration: any, data: unknown): Promise<InitIDPAuthResult> {
|
|
@@ -8,7 +8,7 @@ export class IdPMock implements IdentityProviderHandler<any> {
|
|
|
8
8
|
})
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
processResponse(configuration: any, responseData: any): Promise<
|
|
11
|
+
processResponse(configuration: any, responseData: any): Promise<IDPResponse> {
|
|
12
12
|
return Promise.resolve({
|
|
13
13
|
externalIdentifier: configuration.externalIdentifier,
|
|
14
14
|
email: configuration.email,
|