@authup/server-core 1.0.0-beta.50 → 1.0.0-beta.51
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/adapters/database/domains/client-permission/entity.d.ts +2 -1
- package/dist/adapters/database/domains/client-permission/entity.d.ts.map +1 -1
- package/dist/adapters/database/domains/client-permission/entity.mjs +6 -0
- package/dist/adapters/database/domains/client-permission/entity.mjs.map +1 -1
- package/dist/adapters/database/domains/robot-permission/entity.d.ts +2 -1
- package/dist/adapters/database/domains/robot-permission/entity.d.ts.map +1 -1
- package/dist/adapters/database/domains/robot-permission/entity.mjs +6 -0
- package/dist/adapters/database/domains/robot-permission/entity.mjs.map +1 -1
- package/dist/adapters/database/domains/robot-role/entity.mjs +1 -1
- package/dist/adapters/database/domains/robot-role/entity.mjs.map +1 -1
- package/dist/adapters/database/domains/role-permission/entity.d.ts +2 -1
- package/dist/adapters/database/domains/role-permission/entity.d.ts.map +1 -1
- package/dist/adapters/database/domains/role-permission/entity.mjs +6 -0
- package/dist/adapters/database/domains/role-permission/entity.mjs.map +1 -1
- package/dist/adapters/database/domains/user-permission/entity.d.ts +2 -1
- package/dist/adapters/database/domains/user-permission/entity.d.ts.map +1 -1
- package/dist/adapters/database/domains/user-permission/entity.mjs +6 -0
- package/dist/adapters/database/domains/user-permission/entity.mjs.map +1 -1
- package/dist/adapters/database/migrations/mysql/1779300000000-Default.d.ts +7 -0
- package/dist/adapters/database/migrations/mysql/1779300000000-Default.d.ts.map +1 -0
- package/dist/adapters/database/migrations/mysql/1779300000000-Default.mjs +85 -0
- package/dist/adapters/database/migrations/mysql/1779300000000-Default.mjs.map +1 -0
- package/dist/adapters/database/migrations/postgres/1779300000000-Default.d.ts +7 -0
- package/dist/adapters/database/migrations/postgres/1779300000000-Default.d.ts.map +1 -0
- package/dist/adapters/database/migrations/postgres/1779300000000-Default.mjs +87 -0
- package/dist/adapters/database/migrations/postgres/1779300000000-Default.mjs.map +1 -0
- package/dist/adapters/http/adapters/index.mjs +2 -2
- package/dist/adapters/http/adapters/oauth2/grant-types/index.mjs +2 -2
- package/dist/adapters/http/adapters/oauth2/grant-types/password.d.ts +2 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/password.d.ts.map +1 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/password.mjs +12 -4
- package/dist/adapters/http/adapters/oauth2/grant-types/password.mjs.map +1 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/types.d.ts +2 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/types.d.ts.map +1 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/utils/credentials.d.ts +1 -0
- package/dist/adapters/http/adapters/oauth2/grant-types/utils/credentials.d.ts.map +1 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/utils/credentials.mjs +1 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/utils/credentials.mjs.map +1 -1
- package/dist/adapters/http/adapters/oauth2/grant-types/utils/index.mjs +2 -2
- package/dist/adapters/http/adapters/oauth2/index.mjs +2 -2
- package/dist/adapters/http/controllers/entities/identity-provider/module.d.ts.map +1 -1
- package/dist/adapters/http/controllers/entities/identity-provider/module.mjs +24 -9
- package/dist/adapters/http/controllers/entities/identity-provider/module.mjs.map +1 -1
- package/dist/adapters/http/controllers/workflows/token/module.d.ts.map +1 -1
- package/dist/adapters/http/controllers/workflows/token/module.mjs +2 -1
- package/dist/adapters/http/controllers/workflows/token/module.mjs.map +1 -1
- package/dist/adapters/http/controllers/workflows/token/types.d.ts +2 -1
- package/dist/adapters/http/controllers/workflows/token/types.d.ts.map +1 -1
- package/dist/adapters/http/index.mjs +3 -3
- package/dist/adapters/http/request/helpers/identity.d.ts +0 -1
- package/dist/adapters/http/request/helpers/identity.d.ts.map +1 -1
- package/dist/adapters/http/request/helpers/identity.mjs +2 -5
- package/dist/adapters/http/request/helpers/identity.mjs.map +1 -1
- package/dist/adapters/http/request/helpers/index.mjs +2 -2
- package/dist/adapters/http/request/index.mjs +2 -2
- package/dist/adapters/http/request/permission/module.mjs +2 -2
- package/dist/adapters/http/request/permission/module.mjs.map +1 -1
- package/dist/app/modules/database/repositories/bindings.d.ts +2 -0
- package/dist/app/modules/database/repositories/bindings.d.ts.map +1 -1
- package/dist/app/modules/database/repositories/bindings.mjs +3 -1
- package/dist/app/modules/database/repositories/bindings.mjs.map +1 -1
- package/dist/app/modules/database/repositories/identity-provider/repository.d.ts.map +1 -1
- package/dist/app/modules/database/repositories/identity-provider/repository.mjs +4 -2
- package/dist/app/modules/database/repositories/identity-provider/repository.mjs.map +1 -1
- package/dist/app/modules/database/repositories/permission-provider/module.d.ts +2 -2
- package/dist/app/modules/database/repositories/permission-provider/module.d.ts.map +1 -1
- package/dist/app/modules/database/repositories/permission-provider/module.mjs +4 -3
- package/dist/app/modules/database/repositories/permission-provider/module.mjs.map +1 -1
- package/dist/app/modules/database/repositories/realm/repository.d.ts.map +1 -1
- package/dist/app/modules/database/repositories/realm/repository.mjs +6 -2
- package/dist/app/modules/database/repositories/realm/repository.mjs.map +1 -1
- package/dist/app/modules/http/modules/controller.d.ts +2 -0
- package/dist/app/modules/http/modules/controller.d.ts.map +1 -1
- package/dist/app/modules/http/modules/controller.mjs +18 -0
- package/dist/app/modules/http/modules/controller.mjs.map +1 -1
- package/dist/app/modules/identity/repositories/client.mjs +2 -2
- package/dist/app/modules/identity/repositories/client.mjs.map +1 -1
- package/dist/app/modules/identity/repositories/robot.mjs +2 -2
- package/dist/app/modules/identity/repositories/robot.mjs.map +1 -1
- package/dist/app/modules/identity/repositories/user.mjs +2 -2
- package/dist/app/modules/identity/repositories/user.mjs.map +1 -1
- package/dist/app/modules/oauth2/repositories/client/repository.mjs +2 -2
- package/dist/app/modules/oauth2/repositories/client/repository.mjs.map +1 -1
- package/dist/app/modules/provisioning/module.d.ts.map +1 -1
- package/dist/app/modules/provisioning/module.mjs +0 -1
- package/dist/app/modules/provisioning/module.mjs.map +1 -1
- package/dist/app/modules/provisioning/sources/default/module.d.ts.map +1 -1
- package/dist/app/modules/provisioning/sources/default/module.mjs +14 -56
- package/dist/app/modules/provisioning/sources/default/module.mjs.map +1 -1
- package/dist/core/entities/client/service.mjs +25 -7
- package/dist/core/entities/client/service.mjs.map +1 -1
- package/dist/core/entities/client-permission/service.d.ts +7 -4
- package/dist/core/entities/client-permission/service.d.ts.map +1 -1
- package/dist/core/entities/client-permission/service.mjs +59 -19
- package/dist/core/entities/client-permission/service.mjs.map +1 -1
- package/dist/core/entities/client-role/service.d.ts +3 -2
- package/dist/core/entities/client-role/service.d.ts.map +1 -1
- package/dist/core/entities/client-role/service.mjs +12 -5
- package/dist/core/entities/client-role/service.mjs.map +1 -1
- package/dist/core/entities/client-scope/service.d.ts +3 -2
- package/dist/core/entities/client-scope/service.d.ts.map +1 -1
- package/dist/core/entities/client-scope/service.mjs +12 -5
- package/dist/core/entities/client-scope/service.mjs.map +1 -1
- package/dist/core/entities/identity-provider-role-mapping/service.d.ts +7 -4
- package/dist/core/entities/identity-provider-role-mapping/service.d.ts.map +1 -1
- package/dist/core/entities/identity-provider-role-mapping/service.mjs +29 -6
- package/dist/core/entities/identity-provider-role-mapping/service.mjs.map +1 -1
- package/dist/core/entities/permission/service.d.ts +3 -5
- package/dist/core/entities/permission/service.d.ts.map +1 -1
- package/dist/core/entities/permission/service.mjs +30 -24
- package/dist/core/entities/permission/service.mjs.map +1 -1
- package/dist/core/entities/permission-policy/service.d.ts +3 -2
- package/dist/core/entities/permission-policy/service.d.ts.map +1 -1
- package/dist/core/entities/permission-policy/service.mjs +12 -5
- package/dist/core/entities/permission-policy/service.mjs.map +1 -1
- package/dist/core/entities/policy/service.d.ts.map +1 -1
- package/dist/core/entities/policy/service.mjs +16 -7
- package/dist/core/entities/policy/service.mjs.map +1 -1
- package/dist/core/entities/realm/service.mjs +4 -4
- package/dist/core/entities/realm/service.mjs.map +1 -1
- package/dist/core/entities/realm/types.d.ts +4 -0
- package/dist/core/entities/realm/types.d.ts.map +1 -1
- package/dist/core/entities/robot/service.d.ts.map +1 -1
- package/dist/core/entities/robot/service.mjs +29 -11
- package/dist/core/entities/robot/service.mjs.map +1 -1
- package/dist/core/entities/robot-permission/service.d.ts +7 -4
- package/dist/core/entities/robot-permission/service.d.ts.map +1 -1
- package/dist/core/entities/robot-permission/service.mjs +59 -19
- package/dist/core/entities/robot-permission/service.mjs.map +1 -1
- package/dist/core/entities/robot-role/service.d.ts +3 -2
- package/dist/core/entities/robot-role/service.d.ts.map +1 -1
- package/dist/core/entities/robot-role/service.mjs +12 -5
- package/dist/core/entities/robot-role/service.mjs.map +1 -1
- package/dist/core/entities/role/service.d.ts.map +1 -1
- package/dist/core/entities/role/service.mjs +16 -7
- package/dist/core/entities/role/service.mjs.map +1 -1
- package/dist/core/entities/role-attribute/service.d.ts.map +1 -1
- package/dist/core/entities/role-attribute/service.mjs +24 -6
- package/dist/core/entities/role-attribute/service.mjs.map +1 -1
- package/dist/core/entities/role-permission/service.d.ts +7 -4
- package/dist/core/entities/role-permission/service.d.ts.map +1 -1
- package/dist/core/entities/role-permission/service.mjs +61 -21
- package/dist/core/entities/role-permission/service.mjs.map +1 -1
- package/dist/core/entities/scope/service.d.ts.map +1 -1
- package/dist/core/entities/scope/service.mjs +16 -7
- package/dist/core/entities/scope/service.mjs.map +1 -1
- package/dist/core/entities/user/service.d.ts.map +1 -1
- package/dist/core/entities/user/service.mjs +28 -10
- package/dist/core/entities/user/service.mjs.map +1 -1
- package/dist/core/entities/user-attribute/service.d.ts.map +1 -1
- package/dist/core/entities/user-attribute/service.mjs +18 -6
- package/dist/core/entities/user-attribute/service.mjs.map +1 -1
- package/dist/core/entities/user-permission/service.d.ts +7 -4
- package/dist/core/entities/user-permission/service.d.ts.map +1 -1
- package/dist/core/entities/user-permission/service.mjs +59 -19
- package/dist/core/entities/user-permission/service.mjs.map +1 -1
- package/dist/core/entities/user-role/service.d.ts +3 -2
- package/dist/core/entities/user-role/service.d.ts.map +1 -1
- package/dist/core/entities/user-role/service.mjs +12 -5
- package/dist/core/entities/user-role/service.mjs.map +1 -1
- package/dist/core/identity/index.mjs +2 -1
- package/dist/core/identity/permission/checker/service.d.ts.map +1 -1
- package/dist/core/identity/permission/checker/service.mjs +6 -4
- package/dist/core/identity/permission/checker/service.mjs.map +1 -1
- package/dist/core/identity/permission/index.d.ts +1 -0
- package/dist/core/identity/permission/index.d.ts.map +1 -1
- package/dist/core/identity/permission/index.mjs +2 -1
- package/dist/core/identity/permission/junction-grant.d.ts +49 -0
- package/dist/core/identity/permission/junction-grant.d.ts.map +1 -0
- package/dist/core/identity/permission/junction-grant.mjs +57 -0
- package/dist/core/identity/permission/junction-grant.mjs.map +1 -0
- package/dist/core/identity/permission/module.d.ts +2 -3
- package/dist/core/identity/permission/module.d.ts.map +1 -1
- package/dist/core/identity/permission/module.mjs +52 -14
- package/dist/core/identity/permission/module.mjs.map +1 -1
- package/dist/core/identity/permission/types.d.ts +22 -2
- package/dist/core/identity/permission/types.d.ts.map +1 -1
- package/dist/core/index.mjs +2 -1
- package/dist/core/provisioning/entities/role/types.d.ts +8 -5
- package/dist/core/provisioning/entities/role/types.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/base.d.ts +3 -0
- package/dist/core/provisioning/synchronizer/base.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/base.mjs +3 -0
- package/dist/core/provisioning/synchronizer/base.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/client/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/client/module.mjs +1 -0
- package/dist/core/provisioning/synchronizer/client/module.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/entity-resolver.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/entity-resolver.mjs +3 -0
- package/dist/core/provisioning/synchronizer/entity-resolver.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/index.mjs +1 -0
- package/dist/core/provisioning/synchronizer/permission/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/permission/module.mjs +2 -1
- package/dist/core/provisioning/synchronizer/permission/module.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/policy/module.d.ts +2 -0
- package/dist/core/provisioning/synchronizer/policy/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/policy/module.mjs +19 -1
- package/dist/core/provisioning/synchronizer/policy/module.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/realm/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/realm/module.mjs +1 -0
- package/dist/core/provisioning/synchronizer/realm/module.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/robot/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/robot/module.mjs +1 -0
- package/dist/core/provisioning/synchronizer/robot/module.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/role/module.d.ts +2 -3
- package/dist/core/provisioning/synchronizer/role/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/role/module.mjs +14 -20
- package/dist/core/provisioning/synchronizer/role/module.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/role/types.d.ts +1 -2
- package/dist/core/provisioning/synchronizer/role/types.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/scope/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/scope/module.mjs +1 -0
- package/dist/core/provisioning/synchronizer/scope/module.mjs.map +1 -1
- package/dist/core/provisioning/synchronizer/user/module.d.ts.map +1 -1
- package/dist/core/provisioning/synchronizer/user/module.mjs +1 -0
- package/dist/core/provisioning/synchronizer/user/module.mjs.map +1 -1
- package/dist/core/security/policy/evaluator.d.ts +4 -4
- package/dist/core/security/policy/evaluator.d.ts.map +1 -1
- package/dist/core/security/policy/evaluator.mjs +19 -18
- package/dist/core/security/policy/evaluator.mjs.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/swagger.json +54 -0
- package/dist/ui/client/.vite/ssr-manifest.json +1017 -639
- package/dist/ui/client/assets/index-Cd3uWit-.js +127 -0
- package/dist/ui/client/assets/index-DoCTwJ8M.css +2 -0
- package/dist/ui/client/index.html +2 -2
- package/dist/ui/server/server.js +11086 -2362
- package/package.json +37 -35
- package/dist/ui/client/assets/index-BFXs98mu.js +0 -102
- package/dist/ui/client/assets/index-C_-HM1P-.css +0 -2
|
@@ -3,24 +3,32 @@ import "node:url";
|
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { PasswordGrantType } from "../../../../../core/oauth2/grant-types/password.mjs";
|
|
5
5
|
import "../../../../../core/index.mjs";
|
|
6
|
-
import { extractClientCredentialsFromRequest } from "./utils/credentials.mjs";
|
|
6
|
+
import { extractClientCredentialsFromRequest, readStringField } from "./utils/credentials.mjs";
|
|
7
7
|
import "./utils/index.mjs";
|
|
8
|
+
import { OAuth2RequestError } from "@authup/specs";
|
|
8
9
|
import { getRequestHeader, getRequestIP } from "routup";
|
|
9
10
|
import { readRequestBody } from "@routup/basic/body";
|
|
10
11
|
//#region src/adapters/http/adapters/oauth2/grant-types/password.ts
|
|
11
12
|
var HTTPPasswordGrant = class extends PasswordGrantType {
|
|
12
13
|
authenticator;
|
|
13
14
|
clientAuthenticator;
|
|
15
|
+
realmRepository;
|
|
14
16
|
constructor(ctx) {
|
|
15
17
|
super(ctx);
|
|
16
18
|
this.authenticator = ctx.authenticator;
|
|
17
19
|
this.clientAuthenticator = ctx.clientAuthenticator;
|
|
20
|
+
this.realmRepository = ctx.realmRepository;
|
|
18
21
|
}
|
|
19
22
|
async runWithRequest(event) {
|
|
20
|
-
const
|
|
23
|
+
const body = await readRequestBody(event);
|
|
24
|
+
const username = readStringField(body, "username");
|
|
25
|
+
const password = readStringField(body, "password");
|
|
26
|
+
if (!username || !password) throw OAuth2RequestError.malformed("username and password must be provided.");
|
|
21
27
|
const { clientId, clientSecret } = await extractClientCredentialsFromRequest(event);
|
|
22
|
-
const
|
|
23
|
-
const
|
|
28
|
+
const realmHint = [readStringField(body, "realm_id"), readStringField(body, "realm_name")].map((value) => value?.trim().toLowerCase()).find((value) => !!value);
|
|
29
|
+
const realm = await this.realmRepository.resolve(realmHint, true);
|
|
30
|
+
const client = clientId ? await this.clientAuthenticator.authenticate(clientId, clientSecret, realm.id) : void 0;
|
|
31
|
+
const user = await this.authenticator.authenticate(username, password, realm.id);
|
|
24
32
|
return this.runWith({
|
|
25
33
|
user,
|
|
26
34
|
client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password.mjs","names":["readRequestBody","getRequestHeader","getRequestIP","PasswordGrantType","extractClientCredentialsFromRequest","HTTPPasswordGrant","authenticator","clientAuthenticator","ctx","runWithRequest","event","body","username","password","
|
|
1
|
+
{"version":3,"file":"password.mjs","names":["OAuth2RequestError","readRequestBody","getRequestHeader","getRequestIP","PasswordGrantType","extractClientCredentialsFromRequest","readStringField","HTTPPasswordGrant","authenticator","clientAuthenticator","realmRepository","ctx","runWithRequest","event","body","username","password","malformed","clientId","clientSecret","realmHint","map","value","trim","toLowerCase","find","realm","resolve","client","authenticate","id","undefined","user","runWith","ipAddress","trustProxy","userAgent"],"sources":["../../../../../../src/adapters/http/adapters/oauth2/grant-types/password.ts"],"sourcesContent":["/*\n * Copyright (c) 2025-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { User } from '@authup/core-kit';\nimport type { OAuth2TokenGrantResponse } from '@authup/specs';\nimport { OAuth2RequestError } from '@authup/specs';\nimport { readRequestBody } from '@routup/basic/body';\nimport type { IAppEvent } from 'routup';\nimport { getRequestHeader, getRequestIP } from 'routup';\nimport type { ICredentialsAuthenticator, IRealmRepository, OAuth2ClientAuthenticator } from '../../../../../core/index.ts';\nimport { PasswordGrantType } from '../../../../../core/index.ts';\nimport type { HTTPOAuth2PasswordGrantContext, IHTTPOAuth2Grant } from './types.ts';\nimport { extractClientCredentialsFromRequest, readStringField } from './utils/index.ts';\n\nexport class HTTPPasswordGrant extends PasswordGrantType implements IHTTPOAuth2Grant {\n protected authenticator : ICredentialsAuthenticator<User>;\n\n protected clientAuthenticator : OAuth2ClientAuthenticator;\n\n protected realmRepository : IRealmRepository;\n\n constructor(ctx: HTTPOAuth2PasswordGrantContext) {\n super(ctx);\n\n this.authenticator = ctx.authenticator;\n this.clientAuthenticator = ctx.clientAuthenticator;\n this.realmRepository = ctx.realmRepository;\n }\n\n async runWithRequest(event: IAppEvent): Promise<OAuth2TokenGrantResponse> {\n const body = await readRequestBody(event);\n\n const username = readStringField(body, 'username');\n const password = readStringField(body, 'password');\n if (!username || !password) {\n throw OAuth2RequestError.malformed('username and password must be provided.');\n }\n\n const { clientId, clientSecret } = await extractClientCredentialsFromRequest(event);\n\n // canonical identifier form: realm names are stored LOWER(TRIM(...))\n const realmHint = [\n readStringField(body, 'realm_id'),\n readStringField(body, 'realm_name'),\n ]\n .map((value) => value?.trim().toLowerCase())\n .find((value) => !!value);\n\n const realm = await this.realmRepository.resolve(realmHint, true);\n\n const client = clientId ?\n await this.clientAuthenticator.authenticate(\n clientId,\n clientSecret,\n realm.id,\n ) :\n undefined;\n\n const user = await this.authenticator.authenticate(username, password, realm.id);\n\n return this.runWith(\n { user, client },\n {\n ipAddress: getRequestIP(event, { trustProxy: true }) ?? undefined,\n userAgent: getRequestHeader(event, 'user-agent') ?? undefined,\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAkBA,IAAaO,oBAAb,cAAuCH,kBAAAA;CACzBI;CAEAC;CAEAC;CAEV,YAAYC,KAAqC;EAC7C,MAAMA,GAAAA;EAEN,KAAKH,gBAAgBG,IAAIH;EACzB,KAAKC,sBAAsBE,IAAIF;EAC/B,KAAKC,kBAAkBC,IAAID;CAC/B;CAEA,MAAME,eAAeC,OAAqD;EACtE,MAAMC,OAAO,MAAMb,gBAAgBY,KAAAA;EAEnC,MAAME,WAAWT,gBAAgBQ,MAAM,UAAA;EACvC,MAAME,WAAWV,gBAAgBQ,MAAM,UAAA;EACvC,IAAI,CAACC,YAAY,CAACC,UACd,MAAMhB,mBAAmBiB,UAAU,yCAAA;EAGvC,MAAM,EAAEC,UAAUC,iBAAiB,MAAMd,oCAAoCQ,KAAAA;EAG7E,MAAMO,YAAY,CACdd,gBAAgBQ,MAAM,UAAA,GACtBR,gBAAgBQ,MAAM,YAAA,CAAA,CACzB,CACIO,KAAKC,UAAUA,OAAOC,KAAAA,CAAAA,CAAOC,YAAAA,CAAAA,CAAAA,CAC7BC,MAAMH,UAAU,CAAC,CAACA,KAAAA;EAEvB,MAAMI,QAAQ,MAAM,KAAKhB,gBAAgBiB,QAAQP,WAAW,IAAA;EAE5D,MAAMQ,SAASV,WACX,MAAM,KAAKT,oBAAoBoB,aAC3BX,UACAC,cACAO,MAAMI,EAAE,IAEZC,KAAAA;EAEJ,MAAMC,OAAO,MAAM,KAAKxB,cAAcqB,aAAad,UAAUC,UAAUU,MAAMI,EAAE;EAE/E,OAAO,KAAKG,QACR;GAAED;GAAMJ;EAAO,GACf;GACIM,WAAW/B,aAAaU,OAAO,EAAEsB,YAAY,KAAK,CAAA,KAAMJ,KAAAA;GACxDK,WAAWlC,iBAAiBW,OAAO,YAAA,KAAiBkB,KAAAA;EACxD,CAAA;CAER;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Client, Robot, User } from '@authup/core-kit';
|
|
2
2
|
import type { OAuth2TokenGrantResponse } from '@authup/specs';
|
|
3
3
|
import type { IAppEvent } from 'routup';
|
|
4
|
-
import type { BaseGrantContext, ICredentialsAuthenticator, IOAuth2AuthorizationCodeVerifier, OAuth2AuthorizeGrantContext, OAuth2ClientAuthenticator, OAuth2PasswordGrantContext, OAuth2RefreshTokenGrantContext } from '../../../../../core/index.ts';
|
|
4
|
+
import type { BaseGrantContext, ICredentialsAuthenticator, IOAuth2AuthorizationCodeVerifier, IRealmRepository, OAuth2AuthorizeGrantContext, OAuth2ClientAuthenticator, OAuth2PasswordGrantContext, OAuth2RefreshTokenGrantContext } from '../../../../../core/index.ts';
|
|
5
5
|
export type HTTPOAuth2AuthorizeGrantContext = OAuth2AuthorizeGrantContext & {
|
|
6
6
|
codeVerifier: IOAuth2AuthorizationCodeVerifier;
|
|
7
7
|
clientAuthenticator: OAuth2ClientAuthenticator;
|
|
@@ -12,6 +12,7 @@ export interface IHTTPOAuth2Grant {
|
|
|
12
12
|
export type HTTPOAuth2PasswordGrantContext = OAuth2PasswordGrantContext & {
|
|
13
13
|
authenticator: ICredentialsAuthenticator<User>;
|
|
14
14
|
clientAuthenticator: OAuth2ClientAuthenticator;
|
|
15
|
+
realmRepository: IRealmRepository;
|
|
15
16
|
};
|
|
16
17
|
export type HTTPOAuth2RefreshTokenGrantContext = OAuth2RefreshTokenGrantContext & {
|
|
17
18
|
clientAuthenticator: OAuth2ClientAuthenticator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/adapters/oauth2/grant-types/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EACR,gBAAgB,EAChB,yBAAyB,EACzB,gCAAgC,EAChC,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,8BAA8B,EACjC,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,+BAA+B,GAAG,2BAA2B,GAAG;IACxE,YAAY,EAAE,gCAAgC,CAAC;IAC/C,mBAAmB,EAAE,yBAAyB,CAAC;CAClD,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC7B,cAAc,CAAC,KAAK,EAAE,SAAS,GAAI,OAAO,CAAC,wBAAwB,CAAC,CAAA;CACvE;AAED,MAAM,MAAM,8BAA8B,GAAG,0BAA0B,GAAG;IACtE,aAAa,EAAG,yBAAyB,CAAC,IAAI,CAAC,CAAC;IAChD,mBAAmB,EAAE,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/adapters/oauth2/grant-types/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EACR,gBAAgB,EAChB,yBAAyB,EACzB,gCAAgC,EAChC,gBAAgB,EAChB,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,8BAA8B,EACjC,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,+BAA+B,GAAG,2BAA2B,GAAG;IACxE,YAAY,EAAE,gCAAgC,CAAC;IAC/C,mBAAmB,EAAE,yBAAyB,CAAC;CAClD,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC7B,cAAc,CAAC,KAAK,EAAE,SAAS,GAAI,OAAO,CAAC,wBAAwB,CAAC,CAAA;CACvE;AAED,MAAM,MAAM,8BAA8B,GAAG,0BAA0B,GAAG;IACtE,aAAa,EAAG,yBAAyB,CAAC,IAAI,CAAC,CAAC;IAChD,mBAAmB,EAAE,yBAAyB,CAAC;IAC/C,eAAe,EAAE,gBAAgB,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG,8BAA8B,GAAG;IAC9E,mBAAmB,EAAE,yBAAyB,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG,gBAAgB,GAAG;IACrE,aAAa,EAAG,yBAAyB,CAAC,MAAM,CAAC,CAAA;CACpD,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG,gBAAgB,GAAG;IACpE,aAAa,EAAG,yBAAyB,CAAC,KAAK,CAAC,CAAA;CACnD,CAAC"}
|
|
@@ -12,4 +12,5 @@ export type ExtractedClientCredentials = {
|
|
|
12
12
|
* request body.
|
|
13
13
|
*/
|
|
14
14
|
export declare function extractClientCredentialsFromRequest(event: IAppEvent): Promise<ExtractedClientCredentials>;
|
|
15
|
+
export declare function readStringField(body: Record<string, any> | undefined, key: string): string | undefined;
|
|
15
16
|
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../../../../../src/adapters/http/adapters/oauth2/grant-types/utils/credentials.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,0BAA0B,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,mCAAmC,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,0BAA0B,CAAC,CA6B/G"}
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../../../../../src/adapters/http/adapters/oauth2/grant-types/utils/credentials.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,0BAA0B,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,mCAAmC,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,0BAA0B,CAAC,CA6B/G;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGtG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.mjs","names":["OAuth2RequestError","readRequestBody","AuthorizationHeaderType","parseAuthorizationHeader","extractClientCredentialsFromRequest","event","body","bodyClientId","readStringField","bodyClientSecret","hasBodyCredentials","basicCredentials","parseBasicCredentials","malformed","clientId","clientSecret","key","value","length","undefined","headerValue","headers","get","header","type","BASIC","formDecode","username","password","decodeURIComponent","replace"],"sources":["../../../../../../../src/adapters/http/adapters/oauth2/grant-types/utils/credentials.ts"],"sourcesContent":["/*\n * Copyright (c) 2025-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { OAuth2RequestError } from '@authup/specs';\nimport { readRequestBody } from '@routup/basic/body';\nimport { AuthorizationHeaderType, parseAuthorizationHeader } from 'hapic';\nimport type { IAppEvent } from 'routup';\n\nexport type ExtractedClientCredentials = {\n clientId?: string,\n clientSecret?: string,\n};\n\n/**\n * Extract client credentials from an OAuth2 token endpoint request.\n *\n * Per RFC 6749 §2.3.1, the server MUST NOT support multiple client\n * authentication methods in a single request. This helper rejects requests\n * that present credentials in BOTH the Basic Authorization header and the\n * request body.\n */\nexport async function extractClientCredentialsFromRequest(event: IAppEvent): Promise<ExtractedClientCredentials> {\n const body = await readRequestBody(event);\n const bodyClientId = readStringField(body, 'client_id');\n const bodyClientSecret = readStringField(body, 'client_secret');\n const hasBodyCredentials = !!bodyClientId || !!bodyClientSecret;\n\n const basicCredentials = parseBasicCredentials(event);\n\n if (hasBodyCredentials && basicCredentials) {\n throw OAuth2RequestError.malformed(\n 'Client credentials must be provided either via Basic Authorization header or request body, not both.',\n );\n }\n\n if (hasBodyCredentials) {\n // Reject stray client_secret without client_id — otherwise grants\n // that gate auth on `if (clientId)` would silently skip\n // authentication and leak through with the secret discarded.\n if (!bodyClientId) {\n throw OAuth2RequestError.malformed('client_secret was provided without client_id.');\n }\n return { clientId: bodyClientId, clientSecret: bodyClientSecret };\n }\n\n if (basicCredentials) {\n return basicCredentials;\n }\n\n return {};\n}\n\
|
|
1
|
+
{"version":3,"file":"credentials.mjs","names":["OAuth2RequestError","readRequestBody","AuthorizationHeaderType","parseAuthorizationHeader","extractClientCredentialsFromRequest","event","body","bodyClientId","readStringField","bodyClientSecret","hasBodyCredentials","basicCredentials","parseBasicCredentials","malformed","clientId","clientSecret","key","value","length","undefined","headerValue","headers","get","header","type","BASIC","formDecode","username","password","decodeURIComponent","replace"],"sources":["../../../../../../../src/adapters/http/adapters/oauth2/grant-types/utils/credentials.ts"],"sourcesContent":["/*\n * Copyright (c) 2025-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { OAuth2RequestError } from '@authup/specs';\nimport { readRequestBody } from '@routup/basic/body';\nimport { AuthorizationHeaderType, parseAuthorizationHeader } from 'hapic';\nimport type { IAppEvent } from 'routup';\n\nexport type ExtractedClientCredentials = {\n clientId?: string,\n clientSecret?: string,\n};\n\n/**\n * Extract client credentials from an OAuth2 token endpoint request.\n *\n * Per RFC 6749 §2.3.1, the server MUST NOT support multiple client\n * authentication methods in a single request. This helper rejects requests\n * that present credentials in BOTH the Basic Authorization header and the\n * request body.\n */\nexport async function extractClientCredentialsFromRequest(event: IAppEvent): Promise<ExtractedClientCredentials> {\n const body = await readRequestBody(event);\n const bodyClientId = readStringField(body, 'client_id');\n const bodyClientSecret = readStringField(body, 'client_secret');\n const hasBodyCredentials = !!bodyClientId || !!bodyClientSecret;\n\n const basicCredentials = parseBasicCredentials(event);\n\n if (hasBodyCredentials && basicCredentials) {\n throw OAuth2RequestError.malformed(\n 'Client credentials must be provided either via Basic Authorization header or request body, not both.',\n );\n }\n\n if (hasBodyCredentials) {\n // Reject stray client_secret without client_id — otherwise grants\n // that gate auth on `if (clientId)` would silently skip\n // authentication and leak through with the secret discarded.\n if (!bodyClientId) {\n throw OAuth2RequestError.malformed('client_secret was provided without client_id.');\n }\n return { clientId: bodyClientId, clientSecret: bodyClientSecret };\n }\n\n if (basicCredentials) {\n return basicCredentials;\n }\n\n return {};\n}\n\nexport function readStringField(body: Record<string, any> | undefined, key: string): string | undefined {\n const value = body?.[key];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction parseBasicCredentials(event: IAppEvent): ExtractedClientCredentials | undefined {\n const headerValue = event.headers.get('authorization');\n if (!headerValue) {\n return undefined;\n }\n\n let header;\n try {\n header = parseAuthorizationHeader(headerValue);\n } catch {\n // Malformed Authorization header — surface as 400 invalid_request\n // rather than letting hapic's error propagate as 500.\n throw OAuth2RequestError.malformed('Malformed Authorization header.');\n }\n\n if (header.type !== AuthorizationHeaderType.BASIC) {\n return undefined;\n }\n\n // RFC 6749 §2.3.1 + Appendix B: client_id and client_secret are\n // application/x-www-form-urlencoded BEFORE base64 encoding in the\n // Authorization header. hapic only base64-decodes; we form-decode here\n // so credentials containing reserved characters (`:`, `+`, `%`, `&`,\n // `=`, etc.) round-trip correctly.\n return {\n clientId: formDecode(header.username),\n clientSecret: formDecode(header.password),\n };\n}\n\nfunction formDecode(value: string): string {\n try {\n // application/x-www-form-urlencoded: '+' represents space; %XX is\n // percent-encoded UTF-8.\n return decodeURIComponent(value.replace(/\\+/g, ' '));\n } catch {\n // Malformed percent-encoding — return raw value rather than\n // throwing; the caller will still validate via authentication.\n return value;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;GAyBA,eAAsBI,oCAAoCC,OAAgB;CACtE,MAAMC,OAAO,MAAML,gBAAgBI,KAAAA;CACnC,MAAME,eAAeC,gBAAgBF,MAAM,WAAA;CAC3C,MAAMG,mBAAmBD,gBAAgBF,MAAM,eAAA;CAC/C,MAAMI,qBAAqB,CAAC,CAACH,gBAAgB,CAAC,CAACE;CAE/C,MAAME,mBAAmBC,sBAAsBP,KAAAA;CAE/C,IAAIK,sBAAsBC,kBACtB,MAAMX,mBAAmBa,UACrB,sGAAA;CAIR,IAAIH,oBAAoB;EAIpB,IAAI,CAACH,cACD,MAAMP,mBAAmBa,UAAU,+CAAA;EAEvC,OAAO;GAAEC,UAAUP;GAAcQ,cAAcN;EAAiB;CACpE;CAEA,IAAIE,kBACA,OAAOA;CAGX,OAAO,CAAC;AACZ;AAEA,SAAgBH,gBAAgBF,MAAuCU,KAAW;CAC9E,MAAMC,QAAQX,OAAOU;CACrB,OAAO,OAAOC,UAAU,YAAYA,MAAMC,SAAS,IAAID,QAAQE,KAAAA;AACnE;AAEA,SAASP,sBAAsBP,OAAgB;CAC3C,MAAMe,cAAcf,MAAMgB,QAAQC,IAAI,eAAA;CACtC,IAAI,CAACF,aACD;CAGJ,IAAIG;CACJ,IAAI;EACAA,SAASpB,yBAAyBiB,WAAAA;CACtC,QAAQ;EAGJ,MAAMpB,mBAAmBa,UAAU,iCAAA;CACvC;CAEA,IAAIU,OAAOC,SAAStB,wBAAwBuB,OACxC;CAQJ,OAAO;EACHX,UAAUY,WAAWH,OAAOI,QAAQ;EACpCZ,cAAcW,WAAWH,OAAOK,QAAQ;CAC5C;AACJ;AAEA,SAASF,WAAWT,OAAa;CAC7B,IAAI;EAGA,OAAOY,mBAAmBZ,MAAMa,QAAQ,OAAO,GAAA,CAAA;CACnD,QAAQ;EAGJ,OAAOb;CACX;AACJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
-
import { extractClientCredentialsFromRequest } from "./credentials.mjs";
|
|
4
|
+
import { extractClientCredentialsFromRequest, readStringField } from "./credentials.mjs";
|
|
5
5
|
import { guessOauth2GrantTypeByRequest } from "./guess.mjs";
|
|
6
|
-
export { extractClientCredentialsFromRequest, guessOauth2GrantTypeByRequest };
|
|
6
|
+
export { extractClientCredentialsFromRequest, guessOauth2GrantTypeByRequest, readStringField };
|
|
@@ -3,7 +3,7 @@ import "node:url";
|
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { HTTPOAuth2Authorizer } from "./authorization/module.mjs";
|
|
5
5
|
import "./authorization/index.mjs";
|
|
6
|
-
import { extractClientCredentialsFromRequest } from "./grant-types/utils/credentials.mjs";
|
|
6
|
+
import { extractClientCredentialsFromRequest, readStringField } from "./grant-types/utils/credentials.mjs";
|
|
7
7
|
import { guessOauth2GrantTypeByRequest } from "./grant-types/utils/guess.mjs";
|
|
8
8
|
import { HTTPOAuth2AuthorizeGrant } from "./grant-types/authorize.mjs";
|
|
9
9
|
import { HTTPClientCredentialsGrant } from "./grant-types/client-credentials.mjs";
|
|
@@ -12,4 +12,4 @@ import { HTTPPasswordGrant } from "./grant-types/password.mjs";
|
|
|
12
12
|
import { HTTPOAuth2RefreshTokenGrant } from "./grant-types/refresh_token.mjs";
|
|
13
13
|
import { HTTPRobotCredentialsGrant } from "./grant-types/robot-credentials.mjs";
|
|
14
14
|
import "./grant-types/index.mjs";
|
|
15
|
-
export { HTTPClientCredentialsGrant, HTTPOAuth2AuthorizeGrant, HTTPOAuth2Authorizer, HTTPOAuth2IdentityGrantType, HTTPOAuth2RefreshTokenGrant, HTTPPasswordGrant, HTTPRobotCredentialsGrant, extractClientCredentialsFromRequest, guessOauth2GrantTypeByRequest };
|
|
15
|
+
export { HTTPClientCredentialsGrant, HTTPOAuth2AuthorizeGrant, HTTPOAuth2Authorizer, HTTPOAuth2IdentityGrantType, HTTPOAuth2RefreshTokenGrant, HTTPPasswordGrant, HTTPRobotCredentialsGrant, extractClientCredentialsFromRequest, guessOauth2GrantTypeByRequest, readStringField };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/controllers/entities/identity-provider/module.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAMxC,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,kBAAkB,CAAC;AAgBzF,OAAO,KAAK,EACR,wBAAwB,EACxB,6BAA6B,EAC7B,2BAA2B,EAC3B,6BAA6B,EAChC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,K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AK,EAAE,SAAS,GAC5B,OAAO,CAAC,gBAAgB,CAAC;IAOvB,YAAY,CACD,GAAG,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS;IAgD1B,WAAW,CACA,GAAG,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS;YA2ElB,KAAK;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/controllers/entities/identity-provider/module.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAMxC,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,kBAAkB,CAAC;AAgBzF,OAAO,KAAK,EACR,wBAAwB,EACxB,6BAA6B,EAC7B,2BAA2B,EAC3B,6BAA6B,EAChC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACR,+BAA+B,EAC/B,2BAA2B,EAC3B,8BAA8B,EAC9B,uCAAuC,EACvC,gCAAgC,EAChC,gBAAgB,EAEnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACH,uCAAuC,EAE1C,MAAM,8BAA8B,CAAC;AAWtC,OAAO,KAAK,EAAE,iCAAiC,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAEvG,qBAEa,0BAA0B;IACnC,SAAS,CAAC,OAAO,EAAE,iCAAiC,CAAC;IAErD,SAAS,CAAC,UAAU,EAAE,2BAA2B,CAAC;IAElD,SAAS,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAE5C,SAAS,CAAC,cAAc,EAAE,+BAA+B,CAAC;IAE1D,SAAS,CAAC,mBAAmB,EAAG,uCAAuC,CAAC;IAExE,SAAS,CAAC,oBAAoB,EAAG,uCAAuC,CAAC;IAEzE,SAAS,CAAC,YAAY,EAAG,gCAAgC,CAAC;IAE1D,SAAS,CAAC,UAAU,EAAG,8BAA8B,CAAC;gBAI1C,GAAG,EAAE,iCAAiC;IAc5C,YAAY,CACF,KAAK,EAAE,SAAS,GAC7B,OAAO,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;IA+BhD,WAAW,CACA,EAAE,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA0BtB,YAAY,CACD,EAAE,EAAE,MAAM,EACd,IAAI,EAAE,6BAA6B,EAChC,KAAK,EAAE,SAAS,GAC5B,OAAO,CAAC,gBAAgB,CAAC;IAKvB,GAAG,CACQ,EAAE,EAAE,MAAM,EACd,IAAI,EAAE,2BAA2B,EAC9B,KAAK,EAAE,SAAS,GAC5B,OAAO,CAAC,gBAAgB,CAAC;IAKvB,YAAY,CACD,EAAE,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,GAC5B,OAAO,CAAC,gBAAgB,CAAC;IA6BvB,WAAW,CACJ,IAAI,EAAE,6BAA6B,EAChC,KAAK,EAAE,SAAS,GAC5B,OAAO,CAAC,gBAAgB,CAAC;IAOvB,YAAY,CACD,GAAG,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS;IAgD1B,WAAW,CACA,GAAG,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS;YA2ElB,KAAK;YA6FL,OAAO;YAYP,sBAAsB;YAWtB,wBAAwB;CAWzC"}
|
|
@@ -16,7 +16,7 @@ import { ForceLoggedInMiddleware } from "../../../middleware/built-in/loggedin/m
|
|
|
16
16
|
import "../../../middleware/index.mjs";
|
|
17
17
|
import { ValidatorGroup, base64URLDecode, isUUID } from "@authup/kit";
|
|
18
18
|
import { IdentityProviderAttributesValidator, IdentityProviderValidator, IdentityType, PermissionName, isOAuth2IdentityProvider, isOpenIDIdentityProvider } from "@authup/core-kit";
|
|
19
|
-
import { BuiltInPolicyType,
|
|
19
|
+
import { BuiltInPolicyType, definePolicyData } from "@authup/access";
|
|
20
20
|
import { BadRequestError, EntityNotFoundError } from "@authup/errors";
|
|
21
21
|
import { OAuth2RequestError } from "@authup/specs";
|
|
22
22
|
import { URL } from "node:url";
|
|
@@ -66,7 +66,10 @@ var IdentityProviderController = class {
|
|
|
66
66
|
for (const datum of data) try {
|
|
67
67
|
await permissionEvaluator.evaluate({
|
|
68
68
|
name: PermissionName.IDENTITY_PROVIDER_READ,
|
|
69
|
-
|
|
69
|
+
data: definePolicyData({
|
|
70
|
+
[BuiltInPolicyType.ATTRIBUTES]: datum,
|
|
71
|
+
[BuiltInPolicyType.REALM_MATCH]: datum.realm_id ?? null
|
|
72
|
+
})
|
|
70
73
|
});
|
|
71
74
|
} catch {}
|
|
72
75
|
} catch {}
|
|
@@ -82,7 +85,10 @@ var IdentityProviderController = class {
|
|
|
82
85
|
try {
|
|
83
86
|
await useRequestPermissionEvaluator(event).evaluate({
|
|
84
87
|
name: PermissionName.IDENTITY_PROVIDER_READ,
|
|
85
|
-
|
|
88
|
+
data: definePolicyData({
|
|
89
|
+
[BuiltInPolicyType.ATTRIBUTES]: entity,
|
|
90
|
+
[BuiltInPolicyType.REALM_MATCH]: entity.realm_id ?? null
|
|
91
|
+
})
|
|
86
92
|
});
|
|
87
93
|
} catch {}
|
|
88
94
|
return entity;
|
|
@@ -101,7 +107,10 @@ var IdentityProviderController = class {
|
|
|
101
107
|
if (!entity) throw new EntityNotFoundError();
|
|
102
108
|
await permissionEvaluator.evaluate({
|
|
103
109
|
name: PermissionName.IDENTITY_PROVIDER_DELETE,
|
|
104
|
-
|
|
110
|
+
data: definePolicyData({
|
|
111
|
+
[BuiltInPolicyType.ATTRIBUTES]: entity,
|
|
112
|
+
[BuiltInPolicyType.REALM_MATCH]: entity.realm_id ?? null
|
|
113
|
+
})
|
|
105
114
|
});
|
|
106
115
|
const { id: entityId } = entity;
|
|
107
116
|
await this.repository.remove(entity);
|
|
@@ -209,16 +218,22 @@ var IdentityProviderController = class {
|
|
|
209
218
|
await this.repository.validateJoinColumns(data);
|
|
210
219
|
if (entity) await permissionEvaluator.evaluate({
|
|
211
220
|
name: PermissionName.IDENTITY_PROVIDER_UPDATE,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
221
|
+
data: definePolicyData({
|
|
222
|
+
[BuiltInPolicyType.ATTRIBUTES]: {
|
|
223
|
+
...entity,
|
|
224
|
+
...data
|
|
225
|
+
},
|
|
226
|
+
[BuiltInPolicyType.REALM_MATCH]: data.realm_id ?? entity.realm_id ?? null
|
|
227
|
+
})
|
|
216
228
|
});
|
|
217
229
|
else {
|
|
218
230
|
if (!data.realm_id) data.realm_id = useRequestIdentityOrFail(event).realmId;
|
|
219
231
|
await permissionEvaluator.evaluate({
|
|
220
232
|
name: PermissionName.IDENTITY_PROVIDER_CREATE,
|
|
221
|
-
|
|
233
|
+
data: definePolicyData({
|
|
234
|
+
[BuiltInPolicyType.ATTRIBUTES]: data,
|
|
235
|
+
[BuiltInPolicyType.REALM_MATCH]: data.realm_id ?? null
|
|
236
|
+
})
|
|
222
237
|
});
|
|
223
238
|
}
|
|
224
239
|
await this.repository.checkUniqueness(data, entity || void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.mjs","names":["BuiltInPolicyType","PolicyData","ValidatorGroup","base64URLDecode","isUUID","DBody","DContext","DController","DDelete","DGet","DPath","DPost","DPut","DTags","getRequestHeader","getRequestIP","sendRedirect","IdentityProviderAttributesValidator","IdentityProviderValidator","IdentityType","PermissionName","isOAuth2IdentityProvider","isOpenIDIdentityProvider","BadRequestError","EntityNotFoundError","resolveURL","useRequestQuery","readRequestBody","OAuth2RequestError","URL","OAuth2AuthorizationCodeRequestValidator","createIdentityProviderOAuth2Authenticator","applyRouteRealmIDToBody","getBodyRealmID","getRequestParamID","getRequestRealmID","useRequestIdentityOrFail","useRequestParamID","useRequestPermissionEvaluator","ForceLoggedInMiddleware","IdentityProviderController","options","repository","realmRepository","accountManager","codeRequestVerifier","codeRequestValidator","stateManager","codeIssuer","ctx","getProviders","event","data","meta","findMany","permissionEvaluator","preEvaluate","name","IDENTITY_PROVIDER_READ","datum","evaluate","input","ATTRIBUTES","getProvider","id","paramId","entity","findOneByIdOrName","editProvider","user","write","updateOnly","put","dropProvider","IDENTITY_PROVIDER_DELETE","findOneBy","entityId","remove","response","status","addProvider","authorizeOut","_id","resolve","authenticator","provider","baseURL","parameters","codeRequest","query","codeRequestDecoded","JSON","parse","malformed","codeRequestValidated","run","verify","client","realm_id","state","saveAuthorizationState","buildRedirectURL","authorizeIn","Error","protocol","verifyAuthorizationState","code","clientId","client_id","authenticate","realm","authorizationCode","issue","response_type","redirect_uri","scope","type","USER","codeRequestKeys","Object","keys","url","codeRequestKey_","codeRequestKey","searchParams","set","href","group","body","realmId","where","IDENTITY_PROVIDER_UPDATE","UPDATE","IDENTITY_PROVIDER_CREATE","CREATE","validator","attributesValidator","attributes","validateJoinColumns","identity","checkUniqueness","undefined","merge","saveWithEA","create","findOneById","save","ip","trustProxy","userAgent","stateInvalid"],"sources":["../../../../../../src/adapters/http/controllers/entities/identity-provider/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BuiltInPolicyType, PolicyData } from '@authup/access';\nimport { ValidatorGroup, base64URLDecode, isUUID } from '@authup/kit';\nimport {\n DBody,\n DContext,\n DController,\n DDelete,\n DGet,\n DPath,\n DPost,\n DPut,\n DTags,\n} from '@routup/decorators';\nimport type { IAppEvent } from 'routup';\nimport {\n getRequestHeader,\n getRequestIP,\n sendRedirect,\n} from 'routup';\nimport type { IdentityProvider, OAuth2AuthorizationCodeRequest } from '@authup/core-kit';\nimport {\n\n IdentityProviderAttributesValidator,\n IdentityProviderValidator,\n IdentityType,\n PermissionName,\n isOAuth2IdentityProvider,\n isOpenIDIdentityProvider,\n} from '@authup/core-kit';\nimport { BadRequestError, EntityNotFoundError } from '@authup/errors';\nimport { resolveURL } from '../../../../../utils/index.ts';\nimport type { AuthorizeParameters } from '@hapic/oauth2';\nimport { useRequestQuery } from '@routup/basic/query';\nimport { readRequestBody } from '@routup/basic/body';\nimport { OAuth2RequestError } from '@authup/specs';\nimport type {\n EntityCollectionResponse,\n IdentityProviderCreatePayload,\n IdentityProviderSavePayload,\n IdentityProviderUpdatePayload,\n} from '@authup/core-http-kit';\nimport { URL } from 'node:url';\nimport type {\n IIdentityProviderAccountManager,\n IIdentityProviderRepository,\n IOAuth2AuthorizationCodeIssuer,\n IOAuth2AuthorizationCodeRequestVerifier,\n IOAuth2AuthorizationStateManager,\n IRealmRepository,\n OAuth2AuthorizationState,\n} from '../../../../../core/index.ts';\nimport {\n OAuth2AuthorizationCodeRequestValidator,\n createIdentityProviderOAuth2Authenticator,\n} from '../../../../../core/index.ts';\nimport {\n applyRouteRealmIDToBody,\n getBodyRealmID,\n getRequestParamID,\n getRequestRealmID,\n useRequestIdentityOrFail,\n useRequestParamID,\n useRequestPermissionEvaluator,\n} from '../../../request/index.ts';\nimport { ForceLoggedInMiddleware } from '../../../middleware/index.ts';\nimport type { IdentityProviderControllerContext, IdentityProviderControllerOptions } from './types.ts';\n\n@DTags('identity')\n@DController(['/identity-providers', '/realms/:realmId/identity-providers'])\nexport class IdentityProviderController {\n protected options: IdentityProviderControllerOptions;\n\n protected repository: IIdentityProviderRepository;\n\n protected realmRepository: IRealmRepository;\n\n protected accountManager: IIdentityProviderAccountManager;\n\n protected codeRequestVerifier : IOAuth2AuthorizationCodeRequestVerifier;\n\n protected codeRequestValidator : OAuth2AuthorizationCodeRequestValidator;\n\n protected stateManager : IOAuth2AuthorizationStateManager;\n\n protected codeIssuer : IOAuth2AuthorizationCodeIssuer;\n\n // ---------------------------------------------------------\n\n constructor(ctx: IdentityProviderControllerContext) {\n this.options = ctx.options;\n this.repository = ctx.repository;\n this.realmRepository = ctx.realmRepository;\n this.accountManager = ctx.accountManager;\n this.codeIssuer = ctx.codeIssuer;\n this.codeRequestVerifier = ctx.codeRequestVerifier;\n this.codeRequestValidator = new OAuth2AuthorizationCodeRequestValidator();\n this.stateManager = ctx.stateManager;\n }\n\n // ---------------------------------------------------------\n\n @DGet('', [])\n async getProviders(\n @DContext() event: IAppEvent,\n ): Promise<EntityCollectionResponse<IdentityProvider>> {\n const {\n data, \n meta, \n } = await this.repository.findMany(useRequestQuery(event));\n\n try {\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_READ });\n\n for (const datum of data) {\n try {\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_READ,\n input: new PolicyData({ [BuiltInPolicyType.ATTRIBUTES]: datum }),\n });\n } catch {\n // do nothing\n }\n }\n } catch {\n // do nothing\n }\n\n return {\n data,\n meta,\n };\n }\n\n @DGet('/:id', [])\n async getProvider(\n @DPath('id') id: string,\n @DContext() event: IAppEvent,\n ): Promise<IdentityProvider> {\n const paramId = useRequestParamID(event, { isUUID: false });\n\n const entity = await this.repository.findOneByIdOrName(\n paramId,\n getRequestRealmID(event),\n );\n\n if (!entity) {\n throw new EntityNotFoundError();\n }\n\n try {\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_READ,\n input: new PolicyData({ [BuiltInPolicyType.ATTRIBUTES]: entity }),\n });\n } catch {\n // do nothing\n }\n\n return entity;\n }\n\n @DPost('/:id', [ForceLoggedInMiddleware])\n async editProvider(\n @DPath('id') id: string,\n @DBody() user: IdentityProviderUpdatePayload,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n return this.write(event, { updateOnly: true });\n }\n\n @DPut('/:id', [ForceLoggedInMiddleware])\n async put(\n @DPath('id') id: string,\n @DBody() user: IdentityProviderSavePayload,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n return this.write(event);\n }\n\n @DDelete('/:id', [ForceLoggedInMiddleware])\n async dropProvider(\n @DPath('id') id: string,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n const paramId = useRequestParamID(event);\n\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_DELETE });\n\n const entity = await this.repository.findOneBy({ id: paramId });\n\n if (!entity) {\n throw new EntityNotFoundError();\n }\n\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_DELETE,\n input: new PolicyData({ [BuiltInPolicyType.ATTRIBUTES]: entity }),\n });\n\n const { id: entityId } = entity;\n\n await this.repository.remove(entity);\n\n entity.id = entityId;\n\n event.response.status = 202;\n\n return entity;\n }\n\n @DPost('', [ForceLoggedInMiddleware])\n async addProvider(\n @DBody() user: IdentityProviderCreatePayload,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n return this.write(event);\n }\n\n // ---------------------------------------------------------\n\n @DGet('/:id/authorize-out', [])\n async authorizeOut(\n @DPath('id') _id: string,\n @DContext() event: IAppEvent,\n ) {\n const id = useRequestParamID(event);\n const entity = await this.resolve(id);\n\n if (!isOAuth2IdentityProvider(entity) && !isOpenIDIdentityProvider(entity)) {\n throw new BadRequestError('Only an identity-provider based on the oauth protocol supports authorize redirect.');\n }\n\n const authenticator = createIdentityProviderOAuth2Authenticator({\n accountManager: this.accountManager,\n provider: entity,\n options: { baseURL: this.options.baseURL },\n });\n\n const parameters : AuthorizeParameters = {};\n\n let codeRequest: OAuth2AuthorizationCodeRequest | undefined;\n const query = useRequestQuery(event);\n if (typeof query.codeRequest === 'string') {\n let codeRequestDecoded: OAuth2AuthorizationCodeRequest;\n\n try {\n codeRequestDecoded = JSON.parse(base64URLDecode(query.codeRequest));\n } catch {\n throw OAuth2RequestError.malformed('The code request is malformed and can not be parsed.');\n }\n\n const codeRequestValidated = await this.codeRequestValidator.run(codeRequestDecoded);\n const data = await this.codeRequestVerifier.verify(codeRequestValidated);\n\n if (\n data.client.realm_id &&\n entity.realm_id &&\n entity.realm_id !== data.client.realm_id\n ) {\n throw OAuth2RequestError.malformed('The provider and client realm do not match.');\n }\n\n codeRequest = data.data;\n }\n\n parameters.state = await this.saveAuthorizationState(event, codeRequest);\n\n return sendRedirect(event, authenticator.buildRedirectURL(parameters));\n }\n\n @DGet('/:id/authorize-in', [])\n async authorizeIn(\n @DPath('id') _id: string,\n @DContext() event: IAppEvent,\n ) {\n const id = useRequestParamID(event);\n\n const entity = await this.resolve(id);\n\n if (!isOAuth2IdentityProvider(entity) && !isOpenIDIdentityProvider(entity)) {\n throw new Error(`The provider protocol ${entity.protocol} is not valid.`);\n }\n\n const data = await this.verifyAuthorizationState(event);\n if (\n entity.realm_id &&\n data.codeRequest &&\n data.codeRequest.realm_id &&\n data.codeRequest.realm_id !== entity.realm_id\n ) {\n throw OAuth2RequestError.malformed('The provider and client realm do not match.');\n }\n\n const { code } = useRequestQuery(event);\n\n const authenticator = createIdentityProviderOAuth2Authenticator({\n accountManager: this.accountManager,\n provider: entity,\n options: {\n baseURL: this.options.baseURL,\n clientId: data.codeRequest?.client_id,\n },\n });\n\n const user = await authenticator.authenticate(code);\n\n const realm = await this.realmRepository.resolve(entity.realm_id, true);\n\n const authorizationCode = await this.codeIssuer.issue(\n {\n response_type: 'code',\n client_id: data.codeRequest?.client_id,\n redirect_uri: data.codeRequest?.redirect_uri,\n scope: data.codeRequest?.scope,\n },\n {\n type: IdentityType.USER,\n data: {\n ...user,\n realm,\n },\n },\n );\n\n if (data.codeRequest) {\n const codeRequestKeys = Object.keys(data.codeRequest);\n\n const url = new URL(resolveURL(this.options.baseURL, 'authorize'));\n for (const codeRequestKey_ of codeRequestKeys) {\n const codeRequestKey = codeRequestKey_ as keyof OAuth2AuthorizationCodeRequest;\n if (data.codeRequest[codeRequestKey]) {\n url.searchParams.set(codeRequestKey, data.codeRequest[codeRequestKey]);\n }\n }\n\n url.searchParams.set('code', authorizationCode.id);\n\n return sendRedirect(event, url.href);\n }\n\n const url = new URL(this.options.baseURL);\n url.searchParams.set('code', authorizationCode.id);\n\n return sendRedirect(event, url.href);\n }\n\n // ---------------------------------------------------------\n\n private async write(event: IAppEvent, options: {\n updateOnly?: boolean\n } = {}): Promise<IdentityProvider> {\n let group: string;\n const id = getRequestParamID(event, { isUUID: false });\n const body = await readRequestBody(event);\n applyRouteRealmIDToBody(event, body);\n const realmId = getRequestRealmID(event) ?? getBodyRealmID(body);\n\n let entity: IdentityProvider | null | undefined;\n if (id) {\n const where: Record<string, any> = {};\n if (isUUID(id)) {\n where.id = id;\n } else {\n where.name = id;\n }\n\n if (realmId) {\n where.realm_id = realmId;\n }\n\n entity = await this.repository.findOneBy(where);\n if (!entity && options.updateOnly) {\n throw new EntityNotFoundError();\n }\n } else if (options.updateOnly) {\n throw new EntityNotFoundError();\n }\n\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n if (entity) {\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_UPDATE });\n\n group = ValidatorGroup.UPDATE;\n } else {\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_CREATE });\n\n group = ValidatorGroup.CREATE;\n }\n\n const validator = new IdentityProviderValidator();\n const data = await validator.run(body, { group });\n\n const attributesValidator = new IdentityProviderAttributesValidator();\n const attributes = await attributesValidator.run(body);\n\n await this.repository.validateJoinColumns(data);\n\n if (entity) {\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_UPDATE,\n input: new PolicyData({\n [BuiltInPolicyType.ATTRIBUTES]: {\n ...entity,\n ...data,\n },\n }),\n });\n } else {\n if (!data.realm_id) {\n const identity = useRequestIdentityOrFail(event);\n data.realm_id = identity.realmId;\n }\n\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_CREATE,\n input: new PolicyData({ [BuiltInPolicyType.ATTRIBUTES]: data }),\n });\n }\n\n await this.repository.checkUniqueness(data, entity || undefined);\n\n if (entity) {\n entity = this.repository.merge(entity, data);\n await this.repository.saveWithEA(entity, attributes);\n\n event.response.status = 202;\n\n return entity;\n }\n\n entity = this.repository.create(data);\n await this.repository.saveWithEA(entity, attributes);\n\n event.response.status = 201;\n\n return entity;\n }\n\n // ---------------------------------------------------------\n\n private async resolve(id: string) {\n const entity = await this.repository.findOneById(id);\n\n if (!entity) {\n throw new EntityNotFoundError();\n }\n\n return entity;\n }\n\n // ---------------------------------------------------------\n\n private async saveAuthorizationState(\n event: IAppEvent,\n codeRequest?: OAuth2AuthorizationCodeRequest,\n ) : Promise<string> {\n return this.stateManager.save({\n codeRequest,\n ip: getRequestIP(event, { trustProxy: true }) ?? '',\n userAgent: getRequestHeader(event, 'user-agent') ?? undefined,\n });\n }\n\n private async verifyAuthorizationState(event: IAppEvent): Promise<OAuth2AuthorizationState> {\n const query = useRequestQuery(event);\n if (typeof query.state !== 'string') {\n throw OAuth2RequestError.stateInvalid();\n }\n\n return this.stateManager.verify(query.state, {\n ip: getRequestIP(event, { trustProxy: true }) ?? '',\n userAgent: getRequestHeader(event, 'user-agent') ?? undefined,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,IAAawC,6BAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAIV,YAAYC,KAAwC;EAChD,KAAKR,UAAUQ,IAAIR;EACnB,KAAKC,aAAaO,IAAIP;EACtB,KAAKC,kBAAkBM,IAAIN;EAC3B,KAAKC,iBAAiBK,IAAIL;EAC1B,KAAKI,aAAaC,IAAID;EACtB,KAAKH,sBAAsBI,IAAIJ;EAC/B,KAAKC,uBAAuB,IAAIhB,wCAAAA;EAChC,KAAKiB,eAAeE,IAAIF;CAC5B;CAIA,MACMG,aACF,OACmD;EACnD,MAAM,EACFE,MACAC,SACA,MAAM,KAAKX,WAAWY,SAAS5B,gBAAgByB,KAAAA,CAAAA;EAEnD,IAAI;GACA,MAAMI,sBAAsBjB,8BAA8Ba,KAAAA;GAC1D,MAAMI,oBAAoBC,YAAY,EAAEC,MAAMrC,eAAesC,uBAAuB,CAAA;GAEpF,KAAK,MAAMC,SAASP,MAChB,IAAI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OAAO0C;CACX;CAIA,MAAckC,uBACVjD,OACAqC,aACgB;EAChB,OAAO,KAAKzC,aAAamG,KAAK;GAC1B1D;GACA2D,IAAIpI,aAAaoC,OAAO,EAAEiG,YAAY,KAAK,CAAA,KAAM;GACjDC,WAAWvI,iBAAiBqC,OAAO,YAAA,KAAiB0F,KAAAA;EACxD,CAAA;CACJ;CAEA,MAAcpC,yBAAyBtD,OAAqD;EACxF,MAAMsC,QAAQ/D,gBAAgByB,KAAAA;EAC9B,IAAI,OAAOsC,MAAMU,UAAU,UACvB,MAAMvE,mBAAmB0H,aAAY;EAGzC,OAAO,KAAKvG,aAAaiD,OAAOP,MAAMU,OAAO;GACzCgD,IAAIpI,aAAaoC,OAAO,EAAEiG,YAAY,KAAK,CAAA,KAAM;GACjDC,WAAWvI,iBAAiBqC,OAAO,YAAA,KAAiB0F,KAAAA;EACxD,CAAA;CACJ;AACJ;;;;;;;;;;;;;;;;;gBA1ToBtG,uBAAAA,CAAAA;;;;;;;;;;;;;eASDA,uBAAAA,CAAAA;;;;;;;;;;;;;kBASGA,uBAAAA,CAAAA;;;;;;;;YAgCNA,uBAAAA,CAAAA;;;;;;;;;;;;;;;;;;;;;;;;;cAjJF,uBAAuB,qCAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"module.mjs","names":["BuiltInPolicyType","definePolicyData","ValidatorGroup","base64URLDecode","isUUID","DBody","DContext","DController","DDelete","DGet","DPath","DPost","DPut","DTags","getRequestHeader","getRequestIP","sendRedirect","IdentityProviderAttributesValidator","IdentityProviderValidator","IdentityType","PermissionName","isOAuth2IdentityProvider","isOpenIDIdentityProvider","BadRequestError","EntityNotFoundError","resolveURL","useRequestQuery","readRequestBody","OAuth2RequestError","URL","OAuth2AuthorizationCodeRequestValidator","createIdentityProviderOAuth2Authenticator","applyRouteRealmIDToBody","getBodyRealmID","getRequestParamID","getRequestRealmID","useRequestIdentityOrFail","useRequestParamID","useRequestPermissionEvaluator","ForceLoggedInMiddleware","IdentityProviderController","options","repository","realmRepository","accountManager","codeRequestVerifier","codeRequestValidator","stateManager","codeIssuer","ctx","getProviders","event","data","meta","findMany","permissionEvaluator","preEvaluate","name","IDENTITY_PROVIDER_READ","datum","evaluate","ATTRIBUTES","REALM_MATCH","realm_id","getProvider","id","paramId","entity","findOneByIdOrName","editProvider","user","write","updateOnly","put","dropProvider","IDENTITY_PROVIDER_DELETE","findOneBy","entityId","remove","response","status","addProvider","authorizeOut","_id","resolve","authenticator","provider","baseURL","parameters","codeRequest","query","codeRequestDecoded","JSON","parse","malformed","codeRequestValidated","run","verify","client","state","saveAuthorizationState","buildRedirectURL","authorizeIn","Error","protocol","verifyAuthorizationState","code","clientId","client_id","authenticate","realm","authorizationCode","issue","response_type","redirect_uri","scope","type","USER","codeRequestKeys","Object","keys","url","codeRequestKey_","codeRequestKey","searchParams","set","href","group","body","realmId","where","IDENTITY_PROVIDER_UPDATE","UPDATE","IDENTITY_PROVIDER_CREATE","CREATE","validator","attributesValidator","attributes","validateJoinColumns","identity","checkUniqueness","undefined","merge","saveWithEA","create","findOneById","save","ip","trustProxy","userAgent","stateInvalid"],"sources":["../../../../../../src/adapters/http/controllers/entities/identity-provider/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BuiltInPolicyType, definePolicyData } from '@authup/access';\nimport { ValidatorGroup, base64URLDecode, isUUID } from '@authup/kit';\nimport {\n DBody,\n DContext,\n DController,\n DDelete,\n DGet,\n DPath,\n DPost,\n DPut,\n DTags,\n} from '@routup/decorators';\nimport type { IAppEvent } from 'routup';\nimport {\n getRequestHeader,\n getRequestIP,\n sendRedirect,\n} from 'routup';\nimport type { IdentityProvider, OAuth2AuthorizationCodeRequest } from '@authup/core-kit';\nimport {\n\n IdentityProviderAttributesValidator,\n IdentityProviderValidator,\n IdentityType,\n PermissionName,\n isOAuth2IdentityProvider,\n isOpenIDIdentityProvider,\n} from '@authup/core-kit';\nimport { BadRequestError, EntityNotFoundError } from '@authup/errors';\nimport { resolveURL } from '../../../../../utils/index.ts';\nimport type { AuthorizeParameters } from '@hapic/oauth2';\nimport { useRequestQuery } from '@routup/basic/query';\nimport { readRequestBody } from '@routup/basic/body';\nimport { OAuth2RequestError } from '@authup/specs';\nimport type {\n EntityCollectionResponse,\n IdentityProviderCreatePayload,\n IdentityProviderSavePayload,\n IdentityProviderUpdatePayload,\n} from '@authup/core-http-kit';\nimport { URL } from 'node:url';\nimport type {\n IIdentityProviderAccountManager,\n IIdentityProviderRepository,\n IOAuth2AuthorizationCodeIssuer,\n IOAuth2AuthorizationCodeRequestVerifier,\n IOAuth2AuthorizationStateManager,\n IRealmRepository,\n OAuth2AuthorizationState,\n} from '../../../../../core/index.ts';\nimport {\n OAuth2AuthorizationCodeRequestValidator,\n createIdentityProviderOAuth2Authenticator,\n} from '../../../../../core/index.ts';\nimport {\n applyRouteRealmIDToBody,\n getBodyRealmID,\n getRequestParamID,\n getRequestRealmID,\n useRequestIdentityOrFail,\n useRequestParamID,\n useRequestPermissionEvaluator,\n} from '../../../request/index.ts';\nimport { ForceLoggedInMiddleware } from '../../../middleware/index.ts';\nimport type { IdentityProviderControllerContext, IdentityProviderControllerOptions } from './types.ts';\n\n@DTags('identity')\n@DController(['/identity-providers', '/realms/:realmId/identity-providers'])\nexport class IdentityProviderController {\n protected options: IdentityProviderControllerOptions;\n\n protected repository: IIdentityProviderRepository;\n\n protected realmRepository: IRealmRepository;\n\n protected accountManager: IIdentityProviderAccountManager;\n\n protected codeRequestVerifier : IOAuth2AuthorizationCodeRequestVerifier;\n\n protected codeRequestValidator : OAuth2AuthorizationCodeRequestValidator;\n\n protected stateManager : IOAuth2AuthorizationStateManager;\n\n protected codeIssuer : IOAuth2AuthorizationCodeIssuer;\n\n // ---------------------------------------------------------\n\n constructor(ctx: IdentityProviderControllerContext) {\n this.options = ctx.options;\n this.repository = ctx.repository;\n this.realmRepository = ctx.realmRepository;\n this.accountManager = ctx.accountManager;\n this.codeIssuer = ctx.codeIssuer;\n this.codeRequestVerifier = ctx.codeRequestVerifier;\n this.codeRequestValidator = new OAuth2AuthorizationCodeRequestValidator();\n this.stateManager = ctx.stateManager;\n }\n\n // ---------------------------------------------------------\n\n @DGet('', [])\n async getProviders(\n @DContext() event: IAppEvent,\n ): Promise<EntityCollectionResponse<IdentityProvider>> {\n const {\n data, \n meta, \n } = await this.repository.findMany(useRequestQuery(event));\n\n try {\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_READ });\n\n for (const datum of data) {\n try {\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_READ,\n data: definePolicyData({ [BuiltInPolicyType.ATTRIBUTES]: datum, [BuiltInPolicyType.REALM_MATCH]: datum.realm_id ?? null }),\n });\n } catch {\n // do nothing\n }\n }\n } catch {\n // do nothing\n }\n\n return {\n data,\n meta,\n };\n }\n\n @DGet('/:id', [])\n async getProvider(\n @DPath('id') id: string,\n @DContext() event: IAppEvent,\n ): Promise<IdentityProvider> {\n const paramId = useRequestParamID(event, { isUUID: false });\n\n const entity = await this.repository.findOneByIdOrName(\n paramId,\n getRequestRealmID(event),\n );\n\n if (!entity) {\n throw new EntityNotFoundError();\n }\n\n try {\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_READ,\n data: definePolicyData({ [BuiltInPolicyType.ATTRIBUTES]: entity, [BuiltInPolicyType.REALM_MATCH]: entity.realm_id ?? null }),\n });\n } catch {\n // do nothing\n }\n\n return entity;\n }\n\n @DPost('/:id', [ForceLoggedInMiddleware])\n async editProvider(\n @DPath('id') id: string,\n @DBody() user: IdentityProviderUpdatePayload,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n return this.write(event, { updateOnly: true });\n }\n\n @DPut('/:id', [ForceLoggedInMiddleware])\n async put(\n @DPath('id') id: string,\n @DBody() user: IdentityProviderSavePayload,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n return this.write(event);\n }\n\n @DDelete('/:id', [ForceLoggedInMiddleware])\n async dropProvider(\n @DPath('id') id: string,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n const paramId = useRequestParamID(event);\n\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_DELETE });\n\n const entity = await this.repository.findOneBy({ id: paramId });\n\n if (!entity) {\n throw new EntityNotFoundError();\n }\n\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_DELETE,\n data: definePolicyData({ [BuiltInPolicyType.ATTRIBUTES]: entity, [BuiltInPolicyType.REALM_MATCH]: entity.realm_id ?? null }),\n });\n\n const { id: entityId } = entity;\n\n await this.repository.remove(entity);\n\n entity.id = entityId;\n\n event.response.status = 202;\n\n return entity;\n }\n\n @DPost('', [ForceLoggedInMiddleware])\n async addProvider(\n @DBody() user: IdentityProviderCreatePayload,\n @DContext() event: IAppEvent,\n ) : Promise<IdentityProvider> {\n return this.write(event);\n }\n\n // ---------------------------------------------------------\n\n @DGet('/:id/authorize-out', [])\n async authorizeOut(\n @DPath('id') _id: string,\n @DContext() event: IAppEvent,\n ) {\n const id = useRequestParamID(event);\n const entity = await this.resolve(id);\n\n if (!isOAuth2IdentityProvider(entity) && !isOpenIDIdentityProvider(entity)) {\n throw new BadRequestError('Only an identity-provider based on the oauth protocol supports authorize redirect.');\n }\n\n const authenticator = createIdentityProviderOAuth2Authenticator({\n accountManager: this.accountManager,\n provider: entity,\n options: { baseURL: this.options.baseURL },\n });\n\n const parameters : AuthorizeParameters = {};\n\n let codeRequest: OAuth2AuthorizationCodeRequest | undefined;\n const query = useRequestQuery(event);\n if (typeof query.codeRequest === 'string') {\n let codeRequestDecoded: OAuth2AuthorizationCodeRequest;\n\n try {\n codeRequestDecoded = JSON.parse(base64URLDecode(query.codeRequest));\n } catch {\n throw OAuth2RequestError.malformed('The code request is malformed and can not be parsed.');\n }\n\n const codeRequestValidated = await this.codeRequestValidator.run(codeRequestDecoded);\n const data = await this.codeRequestVerifier.verify(codeRequestValidated);\n\n if (\n data.client.realm_id &&\n entity.realm_id &&\n entity.realm_id !== data.client.realm_id\n ) {\n throw OAuth2RequestError.malformed('The provider and client realm do not match.');\n }\n\n codeRequest = data.data;\n }\n\n parameters.state = await this.saveAuthorizationState(event, codeRequest);\n\n return sendRedirect(event, authenticator.buildRedirectURL(parameters));\n }\n\n @DGet('/:id/authorize-in', [])\n async authorizeIn(\n @DPath('id') _id: string,\n @DContext() event: IAppEvent,\n ) {\n const id = useRequestParamID(event);\n\n const entity = await this.resolve(id);\n\n if (!isOAuth2IdentityProvider(entity) && !isOpenIDIdentityProvider(entity)) {\n throw new Error(`The provider protocol ${entity.protocol} is not valid.`);\n }\n\n const data = await this.verifyAuthorizationState(event);\n if (\n entity.realm_id &&\n data.codeRequest &&\n data.codeRequest.realm_id &&\n data.codeRequest.realm_id !== entity.realm_id\n ) {\n throw OAuth2RequestError.malformed('The provider and client realm do not match.');\n }\n\n const { code } = useRequestQuery(event);\n\n const authenticator = createIdentityProviderOAuth2Authenticator({\n accountManager: this.accountManager,\n provider: entity,\n options: {\n baseURL: this.options.baseURL,\n clientId: data.codeRequest?.client_id,\n },\n });\n\n const user = await authenticator.authenticate(code);\n\n const realm = await this.realmRepository.resolve(entity.realm_id, true);\n\n const authorizationCode = await this.codeIssuer.issue(\n {\n response_type: 'code',\n client_id: data.codeRequest?.client_id,\n redirect_uri: data.codeRequest?.redirect_uri,\n scope: data.codeRequest?.scope,\n },\n {\n type: IdentityType.USER,\n data: {\n ...user,\n realm,\n },\n },\n );\n\n if (data.codeRequest) {\n const codeRequestKeys = Object.keys(data.codeRequest);\n\n const url = new URL(resolveURL(this.options.baseURL, 'authorize'));\n for (const codeRequestKey_ of codeRequestKeys) {\n const codeRequestKey = codeRequestKey_ as keyof OAuth2AuthorizationCodeRequest;\n if (data.codeRequest[codeRequestKey]) {\n url.searchParams.set(codeRequestKey, data.codeRequest[codeRequestKey]);\n }\n }\n\n url.searchParams.set('code', authorizationCode.id);\n\n return sendRedirect(event, url.href);\n }\n\n const url = new URL(this.options.baseURL);\n url.searchParams.set('code', authorizationCode.id);\n\n return sendRedirect(event, url.href);\n }\n\n // ---------------------------------------------------------\n\n private async write(event: IAppEvent, options: {\n updateOnly?: boolean\n } = {}): Promise<IdentityProvider> {\n let group: string;\n const id = getRequestParamID(event, { isUUID: false });\n const body = await readRequestBody(event);\n applyRouteRealmIDToBody(event, body);\n const realmId = getRequestRealmID(event) ?? getBodyRealmID(body);\n\n let entity: IdentityProvider | null | undefined;\n if (id) {\n const where: Record<string, any> = {};\n if (isUUID(id)) {\n where.id = id;\n } else {\n where.name = id;\n }\n\n if (realmId) {\n where.realm_id = realmId;\n }\n\n entity = await this.repository.findOneBy(where);\n if (!entity && options.updateOnly) {\n throw new EntityNotFoundError();\n }\n } else if (options.updateOnly) {\n throw new EntityNotFoundError();\n }\n\n const permissionEvaluator = useRequestPermissionEvaluator(event);\n if (entity) {\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_UPDATE });\n\n group = ValidatorGroup.UPDATE;\n } else {\n await permissionEvaluator.preEvaluate({ name: PermissionName.IDENTITY_PROVIDER_CREATE });\n\n group = ValidatorGroup.CREATE;\n }\n\n const validator = new IdentityProviderValidator();\n const data = await validator.run(body, { group });\n\n const attributesValidator = new IdentityProviderAttributesValidator();\n const attributes = await attributesValidator.run(body);\n\n await this.repository.validateJoinColumns(data);\n\n if (entity) {\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_UPDATE,\n data: definePolicyData({\n [BuiltInPolicyType.ATTRIBUTES]: {\n ...entity,\n ...data,\n },\n [BuiltInPolicyType.REALM_MATCH]: data.realm_id ?? entity.realm_id ?? null,\n }),\n });\n } else {\n if (!data.realm_id) {\n const identity = useRequestIdentityOrFail(event);\n data.realm_id = identity.realmId;\n }\n\n await permissionEvaluator.evaluate({\n name: PermissionName.IDENTITY_PROVIDER_CREATE,\n data: definePolicyData({ [BuiltInPolicyType.ATTRIBUTES]: data, [BuiltInPolicyType.REALM_MATCH]: data.realm_id ?? null }),\n });\n }\n\n await this.repository.checkUniqueness(data, entity || undefined);\n\n if (entity) {\n entity = this.repository.merge(entity, data);\n await this.repository.saveWithEA(entity, attributes);\n\n event.response.status = 202;\n\n return entity;\n }\n\n entity = this.repository.create(data);\n await this.repository.saveWithEA(entity, attributes);\n\n event.response.status = 201;\n\n return entity;\n }\n\n // ---------------------------------------------------------\n\n private async resolve(id: string) {\n const entity = await this.repository.findOneById(id);\n\n if (!entity) {\n throw new EntityNotFoundError();\n }\n\n return entity;\n }\n\n // ---------------------------------------------------------\n\n private async saveAuthorizationState(\n event: IAppEvent,\n codeRequest?: OAuth2AuthorizationCodeRequest,\n ) : Promise<string> {\n return this.stateManager.save({\n codeRequest,\n ip: getRequestIP(event, { trustProxy: true }) ?? '',\n userAgent: getRequestHeader(event, 'user-agent') ?? undefined,\n });\n }\n\n private async verifyAuthorizationState(event: IAppEvent): Promise<OAuth2AuthorizationState> {\n const query = useRequestQuery(event);\n if (typeof query.state !== 'string') {\n throw OAuth2RequestError.stateInvalid();\n }\n\n return this.stateManager.verify(query.state, {\n ip: getRequestIP(event, { trustProxy: true }) ?? '',\n userAgent: getRequestHeader(event, 'user-agent') ?? undefined,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,IAAawC,6BAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAIV,YAAYC,KAAwC;EAChD,KAAKR,UAAUQ,IAAIR;EACnB,KAAKC,aAAaO,IAAIP;EACtB,KAAKC,kBAAkBM,IAAIN;EAC3B,KAAKC,iBAAiBK,IAAIL;EAC1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BAAAA,CAAAA;;;;;;;;;;;;;kBASGA,uBAAAA,CAAAA;;;;;;;;YAgCNA,uBAAAA,CAAAA;;;;;;;;;;;;;;;;;;;;;;;;;cAjJF,uBAAuB,qCAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/controllers/workflows/token/module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gCAAgC,EAAyB,MAAM,eAAe,CAAC;AACvH,OAAO,EAA4C,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAQ3F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EACR,2BAA2B,EAC3B,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACvB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAWnE,qBAEa,eAAe;IACxB,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAEjD,SAAS,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;IAEhD,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC;IAE9C,SAAS,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAE5C,SAAS,CAAC,gBAAgB,EAAG,iBAAiB,CAAC;IAE/C,SAAS,CAAC,0BAA0B,EAAG,2BAA2B,CAAC;IAEnE,SAAS,CAAC,WAAW,EAAG,MAAM,CAAC,GAAG,gBAAgB,EAAE,EAAE,gBAAgB,CAAC,CAAC;gBAI5D,GAAG,EAAE,sBAAsB;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/controllers/workflows/token/module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB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ator: ctx.oauth2ClientAuthenticator,
|
|
73
|
-
sessionManager: ctx.sessionManager
|
|
73
|
+
sessionManager: ctx.sessionManager,
|
|
74
|
+
realmRepository: ctx.realmRepository
|
|
74
75
|
}),
|
|
75
76
|
[OAuth2TokenGrant.REFRESH_TOKEN]: new HTTPOAuth2RefreshTokenGrant({
|
|
76
77
|
accessTokenIssuer: ctx.accessTokenIssuer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.mjs","names":["OAuth2GrantTypeError","OAuth2RequestError","OAuth2TokenGrant","DContext","DController","DGet","DPost","DTags","buildPermissionKey","toOAuth2Error","OAuth2OpenIDClaimsBuilder","HTTPClientCredentialsGrant","HTTPOAuth2AuthorizeGrant","HTTPOAuth2RefreshTokenGrant","HTTPPasswordGrant","HTTPRobotCredentialsGrant","guessOauth2GrantTypeByRequest","extractTokenFromRequest","TokenController","refreshTokenIssuer","accessTokenIssuer","tokenVerifier","tokenRevoker","identityResolver","identityPermissionProvider","tokenGrants","ctx","AUTHORIZATION_CODE","codeVerifier","clientAuthenticator","oauth2ClientAuthenticator","sessionManager","CLIENT_CREDENTIALS","authenticator","ROBOT_CREDENTIALS","robotAuthenticator","PASSWORD","userAuthenticator","REFRESH_TOKEN","getIntrospect","event","postIntrospect","token","payload","verify","skipActiveCheck","sub","sub_kind","identityInvalid","permissions","getFor","id","type","clientId","client_id","realmId","realm_id","identity","resolve","claimsBuilder","claims","fromIdentity","active","jti","isInactive","Object","values","reduce","acc","binding","key","permission","name","e","revokeToken","revoke","response","status","createToken","grantType","unsupported","grant","runWithRequest"],"sources":["../../../../../../src/adapters/http/controllers/workflows/token/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { OAuth2TokenGrantResponse, OAuth2TokenIntrospectionResponse, OAuth2TokenPermission } from '@authup/specs';\nimport { OAuth2GrantTypeError, OAuth2RequestError, OAuth2TokenGrant } from '@authup/specs';\nimport {\n DContext,\n DController,\n DGet,\n DPost,\n DTags,\n} from '@routup/decorators';\nimport type { IAppEvent } from 'routup';\nimport { buildPermissionKey } from '@authup/access';\nimport { toOAuth2Error } from '../../../../../core/oauth2/helpers/index.ts';\nimport type { TokenControllerContext } from './types.ts';\nimport type {\n IIdentityPermissionProvider,\n IIdentityResolver,\n IOAuth2TokenIssuer,\n IOAuth2TokenRevoker,\n IOAuth2TokenVerifier,\n} from '../../../../../core/index.ts';\nimport { OAuth2OpenIDClaimsBuilder } from '../../../../../core/index.ts';\nimport type { IHTTPOAuth2Grant } from '../../../adapters/index.ts';\nimport {\n HTTPClientCredentialsGrant,\n HTTPOAuth2AuthorizeGrant,\n HTTPOAuth2RefreshTokenGrant,\n HTTPPasswordGrant,\n HTTPRobotCredentialsGrant,\n guessOauth2GrantTypeByRequest,\n} from '../../../adapters/index.ts';\nimport { extractTokenFromRequest } from './utils/index.ts';\n\n@DTags('auth')\n@DController('/token')\nexport class TokenController {\n protected refreshTokenIssuer: IOAuth2TokenIssuer;\n\n protected accessTokenIssuer: IOAuth2TokenIssuer;\n\n protected tokenVerifier: IOAuth2TokenVerifier;\n\n protected tokenRevoker: IOAuth2TokenRevoker;\n\n protected identityResolver : IIdentityResolver;\n\n protected identityPermissionProvider : IIdentityPermissionProvider;\n\n protected tokenGrants : Record<`${OAuth2TokenGrant}`, IHTTPOAuth2Grant>;\n\n // -------------------------------------------\n\n constructor(ctx: TokenControllerContext) {\n this.refreshTokenIssuer = ctx.refreshTokenIssuer;\n this.accessTokenIssuer = ctx.accessTokenIssuer;\n this.tokenVerifier = ctx.tokenVerifier;\n this.tokenRevoker = ctx.tokenRevoker;\n this.identityResolver = ctx.identityResolver;\n this.identityPermissionProvider = ctx.identityPermissionProvider;\n\n this.tokenGrants = {\n [OAuth2TokenGrant.AUTHORIZATION_CODE]: new HTTPOAuth2AuthorizeGrant({\n codeVerifier: ctx.codeVerifier,\n clientAuthenticator: ctx.oauth2ClientAuthenticator,\n accessTokenIssuer: ctx.accessTokenIssuer,\n refreshTokenIssuer: ctx.refreshTokenIssuer,\n sessionManager: ctx.sessionManager,\n }),\n [OAuth2TokenGrant.CLIENT_CREDENTIALS]: new HTTPClientCredentialsGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n authenticator: ctx.clientAuthenticator,\n sessionManager: ctx.sessionManager,\n }),\n [OAuth2TokenGrant.ROBOT_CREDENTIALS]: new HTTPRobotCredentialsGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n authenticator: ctx.robotAuthenticator,\n sessionManager: ctx.sessionManager,\n }),\n [OAuth2TokenGrant.PASSWORD]: new HTTPPasswordGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n refreshTokenIssuer: ctx.refreshTokenIssuer,\n authenticator: ctx.userAuthenticator,\n clientAuthenticator: ctx.oauth2ClientAuthenticator,\n sessionManager: ctx.sessionManager,\n }),\n [OAuth2TokenGrant.REFRESH_TOKEN]: new HTTPOAuth2RefreshTokenGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n refreshTokenIssuer: ctx.refreshTokenIssuer,\n tokenVerifier: ctx.tokenVerifier,\n tokenRevoker: ctx.tokenRevoker,\n sessionManager: ctx.sessionManager,\n clientAuthenticator: ctx.oauth2ClientAuthenticator,\n }),\n };\n }\n\n // -------------------------------------------\n\n @DGet('/introspect', [])\n async getIntrospect(@DContext() event: IAppEvent): Promise<OAuth2TokenIntrospectionResponse> {\n return this.postIntrospect(event);\n }\n\n @DPost('/introspect', [])\n async postIntrospect(\n @DContext() event: IAppEvent,\n ): Promise<OAuth2TokenIntrospectionResponse> {\n try {\n const token = await extractTokenFromRequest(event);\n const payload = await this.tokenVerifier.verify(token, { skipActiveCheck: true });\n if (!payload.sub || !payload.sub_kind) {\n throw OAuth2RequestError.identityInvalid();\n }\n\n // todo: only receive client specific permissions\n const permissions = await this.identityPermissionProvider.getFor({\n id: payload.sub,\n type: payload.sub_kind,\n clientId: payload.client_id,\n realmId: payload.realm_id,\n });\n\n const identity = await this.identityResolver.resolve(payload.sub_kind, payload.sub);\n if (!identity) {\n // todo: differentiate between client, robot & user\n throw OAuth2RequestError.identityInvalid();\n }\n\n const claimsBuilder = new OAuth2OpenIDClaimsBuilder();\n const claims = claimsBuilder.fromIdentity(identity);\n\n let active : boolean;\n if (payload.jti) {\n const isInactive = await this.tokenVerifier.isInactive(payload.jti);\n active = !isInactive;\n } else {\n active = false;\n }\n\n return {\n active,\n // todo: permissions property should be removed.\n permissions: Object.values(\n permissions.reduce((acc, binding) => {\n const key = buildPermissionKey(binding.permission);\n if (!acc[key]) {\n acc[key] = {\n name: binding.permission.name,\n client_id: binding.permission.client_id,\n realm_id: binding.permission.realm_id,\n } as OAuth2TokenPermission;\n }\n return acc;\n }, {} as Record<string, OAuth2TokenPermission>),\n ),\n ...payload,\n ...claims,\n };\n } catch (e) {\n throw toOAuth2Error(e);\n }\n }\n\n // ----------------------------------------------------------\n\n @DPost('/revoke', [])\n async revokeToken(\n @DContext() event: IAppEvent,\n ): Promise<null> {\n try {\n const token = await extractTokenFromRequest(event);\n\n const payload = await this.tokenVerifier.verify(token);\n\n await this.tokenRevoker.revoke(payload);\n\n event.response.status = 202;\n return null;\n } catch (e) {\n throw toOAuth2Error(e);\n }\n }\n\n // ----------------------------------------------------------\n\n @DPost('', [])\n async createToken(@DContext() event: IAppEvent): Promise<OAuth2TokenGrantResponse> {\n const grantType = await guessOauth2GrantTypeByRequest(event);\n if (!grantType) {\n throw OAuth2GrantTypeError.unsupported();\n }\n\n const grant = this.tokenGrants[grantType];\n if (!grant) {\n throw OAuth2GrantTypeError.unsupported();\n }\n\n return grant.runWithRequest(event);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKC,SAAA,aAAA,YAAA,QAAA,KAAA,MAAA;;;;;;;;;;;;;;AAoCD,IAAakB,kBAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAI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;CAIA,MACMK,YAAY,OAAiE;EAC/E,MAAMC,YAAY,MAAM/D,8BAA8BwB,KAAAA;EACtD,IAAI,CAACuC,WACD,MAAM/E,qBAAqBgF,YAAW;EAG1C,MAAMC,QAAQ,KAAKxD,YAAYsD;EAC/B,IAAI,CAACE,OACD,MAAMjF,qBAAqBgF,YAAW;EAG1C,OAAOC,MAAMC,eAAe1C,KAAAA;CAChC;AACJ"}
|
|
1
|
+
{"version":3,"file":"module.mjs","names":["OAuth2GrantTypeError","OAuth2RequestError","OAuth2TokenGrant","DContext","DController","DGet","DPost","DTags","buildPermissionKey","toOAuth2Error","OAuth2OpenIDClaimsBuilder","HTTPClientCredentialsGrant","HTTPOAuth2AuthorizeGrant","HTTPOAuth2RefreshTokenGrant","HTTPPasswordGrant","HTTPRobotCredentialsGrant","guessOauth2GrantTypeByRequest","extractTokenFromRequest","TokenController","refreshTokenIssuer","accessTokenIssuer","tokenVerifier","tokenRevoker","identityResolver","identityPermissionProvider","tokenGrants","ctx","AUTHORIZATION_CODE","codeVerifier","clientAuthenticator","oauth2ClientAuthenticator","sessionManager","CLIENT_CREDENTIALS","authenticator","ROBOT_CREDENTIALS","robotAuthenticator","PASSWORD","userAuthenticator","realmRepository","REFRESH_TOKEN","getIntrospect","event","postIntrospect","token","payload","verify","skipActiveCheck","sub","sub_kind","identityInvalid","permissions","getFor","id","type","clientId","client_id","realmId","realm_id","identity","resolve","claimsBuilder","claims","fromIdentity","active","jti","isInactive","Object","values","reduce","acc","binding","key","permission","name","e","revokeToken","revoke","response","status","createToken","grantType","unsupported","grant","runWithRequest"],"sources":["../../../../../../src/adapters/http/controllers/workflows/token/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { OAuth2TokenGrantResponse, OAuth2TokenIntrospectionResponse, OAuth2TokenPermission } from '@authup/specs';\nimport { OAuth2GrantTypeError, OAuth2RequestError, OAuth2TokenGrant } from '@authup/specs';\nimport {\n DContext,\n DController,\n DGet,\n DPost,\n DTags,\n} from '@routup/decorators';\nimport type { IAppEvent } from 'routup';\nimport { buildPermissionKey } from '@authup/access';\nimport { toOAuth2Error } from '../../../../../core/oauth2/helpers/index.ts';\nimport type { TokenControllerContext } from './types.ts';\nimport type {\n IIdentityPermissionProvider,\n IIdentityResolver,\n IOAuth2TokenIssuer,\n IOAuth2TokenRevoker,\n IOAuth2TokenVerifier,\n} from '../../../../../core/index.ts';\nimport { OAuth2OpenIDClaimsBuilder } from '../../../../../core/index.ts';\nimport type { IHTTPOAuth2Grant } from '../../../adapters/index.ts';\nimport {\n HTTPClientCredentialsGrant,\n HTTPOAuth2AuthorizeGrant,\n HTTPOAuth2RefreshTokenGrant,\n HTTPPasswordGrant,\n HTTPRobotCredentialsGrant,\n guessOauth2GrantTypeByRequest,\n} from '../../../adapters/index.ts';\nimport { extractTokenFromRequest } from './utils/index.ts';\n\n@DTags('auth')\n@DController('/token')\nexport class TokenController {\n protected refreshTokenIssuer: IOAuth2TokenIssuer;\n\n protected accessTokenIssuer: IOAuth2TokenIssuer;\n\n protected tokenVerifier: IOAuth2TokenVerifier;\n\n protected tokenRevoker: IOAuth2TokenRevoker;\n\n protected identityResolver : IIdentityResolver;\n\n protected identityPermissionProvider : IIdentityPermissionProvider;\n\n protected tokenGrants : Record<`${OAuth2TokenGrant}`, IHTTPOAuth2Grant>;\n\n // -------------------------------------------\n\n constructor(ctx: TokenControllerContext) {\n this.refreshTokenIssuer = ctx.refreshTokenIssuer;\n this.accessTokenIssuer = ctx.accessTokenIssuer;\n this.tokenVerifier = ctx.tokenVerifier;\n this.tokenRevoker = ctx.tokenRevoker;\n this.identityResolver = ctx.identityResolver;\n this.identityPermissionProvider = ctx.identityPermissionProvider;\n\n this.tokenGrants = {\n [OAuth2TokenGrant.AUTHORIZATION_CODE]: new HTTPOAuth2AuthorizeGrant({\n codeVerifier: ctx.codeVerifier,\n clientAuthenticator: ctx.oauth2ClientAuthenticator,\n accessTokenIssuer: ctx.accessTokenIssuer,\n refreshTokenIssuer: ctx.refreshTokenIssuer,\n sessionManager: ctx.sessionManager,\n }),\n [OAuth2TokenGrant.CLIENT_CREDENTIALS]: new HTTPClientCredentialsGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n authenticator: ctx.clientAuthenticator,\n sessionManager: ctx.sessionManager,\n }),\n [OAuth2TokenGrant.ROBOT_CREDENTIALS]: new HTTPRobotCredentialsGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n authenticator: ctx.robotAuthenticator,\n sessionManager: ctx.sessionManager,\n }),\n [OAuth2TokenGrant.PASSWORD]: new HTTPPasswordGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n refreshTokenIssuer: ctx.refreshTokenIssuer,\n authenticator: ctx.userAuthenticator,\n clientAuthenticator: ctx.oauth2ClientAuthenticator,\n sessionManager: ctx.sessionManager,\n realmRepository: ctx.realmRepository,\n }),\n [OAuth2TokenGrant.REFRESH_TOKEN]: new HTTPOAuth2RefreshTokenGrant({\n accessTokenIssuer: ctx.accessTokenIssuer,\n refreshTokenIssuer: ctx.refreshTokenIssuer,\n tokenVerifier: ctx.tokenVerifier,\n tokenRevoker: ctx.tokenRevoker,\n sessionManager: ctx.sessionManager,\n clientAuthenticator: ctx.oauth2ClientAuthenticator,\n }),\n };\n }\n\n // -------------------------------------------\n\n @DGet('/introspect', [])\n async getIntrospect(@DContext() event: IAppEvent): Promise<OAuth2TokenIntrospectionResponse> {\n return this.postIntrospect(event);\n }\n\n @DPost('/introspect', [])\n async postIntrospect(\n @DContext() event: IAppEvent,\n ): Promise<OAuth2TokenIntrospectionResponse> {\n try {\n const token = await extractTokenFromRequest(event);\n const payload = await this.tokenVerifier.verify(token, { skipActiveCheck: true });\n if (!payload.sub || !payload.sub_kind) {\n throw OAuth2RequestError.identityInvalid();\n }\n\n // todo: only receive client specific permissions\n const permissions = await this.identityPermissionProvider.getFor({\n id: payload.sub,\n type: payload.sub_kind,\n clientId: payload.client_id,\n realmId: payload.realm_id,\n });\n\n const identity = await this.identityResolver.resolve(payload.sub_kind, payload.sub);\n if (!identity) {\n // todo: differentiate between client, robot & user\n throw OAuth2RequestError.identityInvalid();\n }\n\n const claimsBuilder = new OAuth2OpenIDClaimsBuilder();\n const claims = claimsBuilder.fromIdentity(identity);\n\n let active : boolean;\n if (payload.jti) {\n const isInactive = await this.tokenVerifier.isInactive(payload.jti);\n active = !isInactive;\n } else {\n active = false;\n }\n\n return {\n active,\n // todo: permissions property should be removed.\n permissions: Object.values(\n permissions.reduce((acc, binding) => {\n const key = buildPermissionKey(binding.permission);\n if (!acc[key]) {\n acc[key] = {\n name: binding.permission.name,\n client_id: binding.permission.client_id,\n realm_id: binding.permission.realm_id,\n } as OAuth2TokenPermission;\n }\n return acc;\n }, {} as Record<string, OAuth2TokenPermission>),\n ),\n ...payload,\n ...claims,\n };\n } catch (e) {\n throw toOAuth2Error(e);\n }\n }\n\n // ----------------------------------------------------------\n\n @DPost('/revoke', [])\n async revokeToken(\n @DContext() event: IAppEvent,\n ): Promise<null> {\n try {\n const token = await extractTokenFromRequest(event);\n\n const payload = await this.tokenVerifier.verify(token);\n\n await this.tokenRevoker.revoke(payload);\n\n event.response.status = 202;\n return null;\n } catch (e) {\n throw toOAuth2Error(e);\n }\n }\n\n // ----------------------------------------------------------\n\n @DPost('', [])\n async createToken(@DContext() event: IAppEvent): Promise<OAuth2TokenGrantResponse> {\n const grantType = await guessOauth2GrantTypeByRequest(event);\n if (!grantType) {\n throw OAuth2GrantTypeError.unsupported();\n }\n\n const grant = this.tokenGrants[grantType];\n if (!grant) {\n throw OAuth2GrantTypeError.unsupported();\n }\n\n return grant.runWithRequest(event);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKC,SAAA,aAAA,YAAA,QAAA,KAAA,MAAA;;;;;;;;;;;;;;AAoCD,IAAakB,kBAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAE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AAG;GACR,MAAMjE,cAAciE,CAAAA;EACxB;CACJ;CAIA,MACMK,YAAY,OAAiE;EAC/E,MAAMC,YAAY,MAAMhE,8BAA8ByB,KAAAA;EACtD,IAAI,CAACuC,WACD,MAAMhF,qBAAqBiF,YAAW;EAG1C,MAAMC,QAAQ,KAAKzD,YAAYuD;EAC/B,IAAI,CAACE,OACD,MAAMlF,qBAAqBiF,YAAW;EAG1C,OAAOC,MAAMC,eAAe1C,KAAAA;CAChC;AACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Client, Robot, User } from '@authup/core-kit';
|
|
2
|
-
import type { ICredentialsAuthenticator, IIdentityPermissionProvider, IIdentityResolver, IOAuth2AuthorizationCodeVerifier, IOAuth2TokenIssuer, IOAuth2TokenRevoker, IOAuth2TokenVerifier, ISessionManager, OAuth2ClientAuthenticator } from '../../../../../core/index.ts';
|
|
2
|
+
import type { ICredentialsAuthenticator, IIdentityPermissionProvider, IIdentityResolver, IOAuth2AuthorizationCodeVerifier, IOAuth2TokenIssuer, IOAuth2TokenRevoker, IOAuth2TokenVerifier, IRealmRepository, ISessionManager, OAuth2ClientAuthenticator } from '../../../../../core/index.ts';
|
|
3
3
|
export type TokenControllerContext = {
|
|
4
4
|
codeVerifier: IOAuth2AuthorizationCodeVerifier;
|
|
5
5
|
accessTokenIssuer: IOAuth2TokenIssuer;
|
|
@@ -13,5 +13,6 @@ export type TokenControllerContext = {
|
|
|
13
13
|
robotAuthenticator: ICredentialsAuthenticator<Robot>;
|
|
14
14
|
userAuthenticator: ICredentialsAuthenticator<User>;
|
|
15
15
|
oauth2ClientAuthenticator: OAuth2ClientAuthenticator;
|
|
16
|
+
realmRepository: IRealmRepository;
|
|
16
17
|
};
|
|
17
18
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/controllers/workflows/token/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EACR,yBAAyB,EACzB,2BAA2B,EAC3B,iBAAiB,EACjB,gCAAgC,EAChC,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,yBAAyB,EAC5B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,sBAAsB,GAAG;IACjC,YAAY,EAAE,gCAAgC,CAAC;IAE/C,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,aAAa,EAAE,oBAAoB,CAAC;IACpC,YAAY,EAAE,mBAAmB,CAAC;IAElC,cAAc,EAAE,eAAe,CAAC;IAEhC,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,0BAA0B,EAAE,2BAA2B,CAAC;IAExD,mBAAmB,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IACtD,kBAAkB,EAAE,yBAAyB,CAAC,KAAK,CAAC,CAAA;IACpD,iBAAiB,EAAE,yBAAyB,CAAC,IAAI,CAAC,CAAA;IAElD,yBAAyB,EAAE,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/adapters/http/controllers/workflows/token/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EACR,yBAAyB,EACzB,2BAA2B,EAC3B,iBAAiB,EACjB,gCAAgC,EAChC,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EAC5B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,sBAAsB,GAAG;IACjC,YAAY,EAAE,gCAAgC,CAAC;IAE/C,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,aAAa,EAAE,oBAAoB,CAAC;IACpC,YAAY,EAAE,mBAAmB,CAAC;IAElC,cAAc,EAAE,eAAe,CAAC;IAEhC,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,0BAA0B,EAAE,2BAA2B,CAAC;IAExD,mBAAmB,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IACtD,kBAAkB,EAAE,yBAAyB,CAAC,KAAK,CAAC,CAAA;IACpD,iBAAiB,EAAE,yBAAyB,CAAC,IAAI,CAAC,CAAA;IAElD,yBAAyB,EAAE,yBAAyB,CAAA;IAEpD,eAAe,EAAE,gBAAgB,CAAA;CACpC,CAAC"}
|
|
@@ -3,7 +3,7 @@ import "node:url";
|
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { RequestHandlerOperation } from "./request/constants.mjs";
|
|
5
5
|
import { setRequestPermissionEvaluator, useRequestPermissionEvaluator } from "./request/permission/helper.mjs";
|
|
6
|
-
import { RequestIdentity,
|
|
6
|
+
import { RequestIdentity, setRequestIdentity, useRequestIdentity, useRequestIdentityOrFail } from "./request/helpers/identity.mjs";
|
|
7
7
|
import { buildActorContext } from "./request/helpers/actor.mjs";
|
|
8
8
|
import { getBodyRealmID } from "./request/helpers/body-realm-id.mjs";
|
|
9
9
|
import { LOCALE_COOKIE, useRequestLocale } from "./request/helpers/locale.mjs";
|
|
@@ -16,7 +16,7 @@ import { setRequestToken, useRequestToken } from "./request/helpers/token.mjs";
|
|
|
16
16
|
import { RequestPermissionEvaluator } from "./request/permission/module.mjs";
|
|
17
17
|
import "./request/index.mjs";
|
|
18
18
|
import { HTTPOAuth2Authorizer } from "./adapters/oauth2/authorization/module.mjs";
|
|
19
|
-
import { extractClientCredentialsFromRequest } from "./adapters/oauth2/grant-types/utils/credentials.mjs";
|
|
19
|
+
import { extractClientCredentialsFromRequest, readStringField } from "./adapters/oauth2/grant-types/utils/credentials.mjs";
|
|
20
20
|
import { guessOauth2GrantTypeByRequest } from "./adapters/oauth2/grant-types/utils/guess.mjs";
|
|
21
21
|
import { HTTPOAuth2AuthorizeGrant } from "./adapters/oauth2/grant-types/authorize.mjs";
|
|
22
22
|
import { HTTPClientCredentialsGrant } from "./adapters/oauth2/grant-types/client-credentials.mjs";
|
|
@@ -85,4 +85,4 @@ import { UserPermissionRequestValidator } from "./controllers/entities/user-perm
|
|
|
85
85
|
import { UserRoleController } from "./controllers/entities/user-role/module.mjs";
|
|
86
86
|
import { UserRoleRequestValidator } from "./controllers/entities/user-role/utils/validation.mjs";
|
|
87
87
|
import "./controllers/index.mjs";
|
|
88
|
-
export { ActivateController, AuthorizationMiddleware, AuthorizeController, ClientController, ClientPermissionController, ClientPermissionRequestValidator, ClientRoleController, ClientRoleRequestValidator, ClientScopeController, ClientScopeRequestValidator, ForceLoggedInMiddleware, ForceUserLoggedInMiddleware, HTTPClientCredentialsGrant, HTTPOAuth2AuthorizeGrant, HTTPOAuth2Authorizer, HTTPOAuth2IdentityGrantType, HTTPOAuth2RefreshTokenGrant, HTTPPasswordGrant, HTTPRobotCredentialsGrant, IdentityProviderController, IdentityProviderRoleMappingController, JwkController, LOCALE_COOKIE, OpenIDController, PasswordForgotController, PasswordResetController, PermissionController, PermissionPolicyController, PolicyAttributesValidator, PolicyController, PolicyValidator, RealmController, RealmResolverMiddleware, RegisterController, RequestHandlerOperation, RequestIdentity, RequestPermissionEvaluator, RobotController, RobotPermissionController, RobotPermissionRequestValidator, RobotRoleController, RobotRoleRequestValidator, RoleAttributeController, RoleAttributeRequestValidator, RoleController, RolePermissionController, RolePermissionRequestValidator, ScopeController, StatusController, TokenController, UI_HTTP_CLIENT_FACTORY_STORE_KEY, UserAttributeController, UserAttributeRequestValidator, UserController, UserPermissionController, UserPermissionRequestValidator, UserRoleController, UserRoleRequestValidator, VITE_SERVER_STORE_KEY, applyRouteRealmIDToBody, buildActorContext, createAuthorizationMiddleware, createLoggerMiddleware, createRealmResolverMiddleware, createSwaggerMiddleware, extractClientCredentialsFromRequest, getBodyRealmID, getJwkRouteHandler, getJwksRouteHandler, getRequestParamID, getRequestRealmID, getRequestStringParam, getRequestStringParamOrFail, guessOauth2GrantTypeByRequest,
|
|
88
|
+
export { ActivateController, AuthorizationMiddleware, AuthorizeController, ClientController, ClientPermissionController, ClientPermissionRequestValidator, ClientRoleController, ClientRoleRequestValidator, ClientScopeController, ClientScopeRequestValidator, ForceLoggedInMiddleware, ForceUserLoggedInMiddleware, HTTPClientCredentialsGrant, HTTPOAuth2AuthorizeGrant, HTTPOAuth2Authorizer, HTTPOAuth2IdentityGrantType, HTTPOAuth2RefreshTokenGrant, HTTPPasswordGrant, HTTPRobotCredentialsGrant, IdentityProviderController, IdentityProviderRoleMappingController, JwkController, LOCALE_COOKIE, OpenIDController, PasswordForgotController, PasswordResetController, PermissionController, PermissionPolicyController, PolicyAttributesValidator, PolicyController, PolicyValidator, RealmController, RealmResolverMiddleware, RegisterController, RequestHandlerOperation, RequestIdentity, RequestPermissionEvaluator, RobotController, RobotPermissionController, RobotPermissionRequestValidator, RobotRoleController, RobotRoleRequestValidator, RoleAttributeController, RoleAttributeRequestValidator, RoleController, RolePermissionController, RolePermissionRequestValidator, ScopeController, StatusController, TokenController, UI_HTTP_CLIENT_FACTORY_STORE_KEY, UserAttributeController, UserAttributeRequestValidator, UserController, UserPermissionController, UserPermissionRequestValidator, UserRoleController, UserRoleRequestValidator, VITE_SERVER_STORE_KEY, applyRouteRealmIDToBody, buildActorContext, createAuthorizationMiddleware, createLoggerMiddleware, createRealmResolverMiddleware, createSwaggerMiddleware, extractClientCredentialsFromRequest, getBodyRealmID, getJwkRouteHandler, getJwksRouteHandler, getRequestParamID, getRequestRealmID, getRequestStringParam, getRequestStringParamOrFail, guessOauth2GrantTypeByRequest, readFromLocations, readStringField, registerAssetsMiddleware, registerBasicMiddleware, registerCorsMiddleware, registerErrorMiddleware, registerPrometheusMiddleware, registerRateLimitMiddleware, registerUIHttpClientMiddleware, sanitizeRelativeRedirect, setRequestIdentity, setRequestPermissionEvaluator, setRequestRealmID, setRequestScopes, setRequestToken, useRequestIdentity, useRequestIdentityOrFail, useRequestLocale, useRequestParamID, useRequestPermissionEvaluator, useRequestScopes, useRequestToken };
|
|
@@ -13,5 +13,4 @@ export declare class RequestIdentity {
|
|
|
13
13
|
export declare function useRequestIdentity(event: IAppEvent): RequestIdentity | undefined;
|
|
14
14
|
export declare function setRequestIdentity(event: IAppEvent, input: Identity | RequestIdentity): void;
|
|
15
15
|
export declare function useRequestIdentityOrFail(event: IAppEvent): RequestIdentity;
|
|
16
|
-
export declare function isRequestIdentityMasterRealmMember(input: RequestIdentity): boolean;
|
|
17
16
|
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/http/request/helpers/identity.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAIxC,qBAAa,eAAe;IACxB,SAAgB,GAAG,EAAG,QAAQ,CAAC;gBAEnB,QAAQ,EAAE,QAAQ;IAI9B,IAAI,QAAQ,QAOX;IAED,IAAI,IAAI,2GAEP;IAED,IAAI,IAAI,gCAEP;IAED,IAAI,EAAE,WAEL;IAED,IAAI,OAAO,WAEV;IAED,IAAI,SAAS,WAEZ;CACJ;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAI,eAAe,GAAG,SAAS,CAEjF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,GAAG,eAAe,GAAI,IAAI,CAU7F;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,GAAI,eAAe,CAO3E
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/http/request/helpers/identity.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAIxC,qBAAa,eAAe;IACxB,SAAgB,GAAG,EAAG,QAAQ,CAAC;gBAEnB,QAAQ,EAAE,QAAQ;IAI9B,IAAI,QAAQ,QAOX;IAED,IAAI,IAAI,2GAEP;IAED,IAAI,IAAI,gCAEP;IAED,IAAI,EAAE,WAEL;IAED,IAAI,OAAO,WAEV;IAED,IAAI,SAAS,WAEZ;CACJ;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAI,eAAe,GAAG,SAAS,CAEjF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,GAAG,eAAe,GAAI,IAAI,CAU7F;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,GAAI,eAAe,CAO3E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
-
import { IdentityType
|
|
4
|
+
import { IdentityType } from "@authup/core-kit";
|
|
5
5
|
import { UnauthorizedError } from "@authup/errors";
|
|
6
6
|
//#region src/adapters/http/request/helpers/identity.ts
|
|
7
7
|
const sym = Symbol("RIdentity");
|
|
@@ -45,10 +45,7 @@ function useRequestIdentityOrFail(event) {
|
|
|
45
45
|
if (!identity) throw new UnauthorizedError();
|
|
46
46
|
return identity;
|
|
47
47
|
}
|
|
48
|
-
function isRequestIdentityMasterRealmMember(input) {
|
|
49
|
-
return input.realmName === REALM_MASTER_NAME;
|
|
50
|
-
}
|
|
51
48
|
//#endregion
|
|
52
|
-
export { RequestIdentity,
|
|
49
|
+
export { RequestIdentity, setRequestIdentity, useRequestIdentity, useRequestIdentityOrFail };
|
|
53
50
|
|
|
54
51
|
//# sourceMappingURL=identity.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.mjs","names":["IdentityType","
|
|
1
|
+
{"version":3,"file":"identity.mjs","names":["IdentityType","UnauthorizedError","sym","Symbol","RequestIdentity","raw","identity","clientId","type","CLIENT","data","id","client_id","realmId","realm_id","realm","realmName","name","useRequestIdentity","event","store","setRequestIdentity","input","useRequestIdentityOrFail"],"sources":["../../../../../src/adapters/http/request/helpers/identity.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Identity } from '@authup/core-kit';\nimport { IdentityType } from '@authup/core-kit';\nimport { UnauthorizedError } from '@authup/errors';\nimport type { IAppEvent } from 'routup';\n\nconst sym = Symbol('RIdentity');\n\nexport class RequestIdentity {\n public readonly raw : Identity;\n\n constructor(identity: Identity) {\n this.raw = identity;\n }\n\n get clientId() {\n const { raw } = this;\n if (raw.type === IdentityType.CLIENT) {\n return raw.data.id;\n }\n\n return raw.data.client_id || null;\n }\n\n get data() {\n return this.raw.data;\n }\n\n get type() {\n return this.raw.type;\n }\n\n get id() {\n return this.raw.data.id;\n }\n\n get realmId() {\n return this.raw.data.realm_id || this.raw.data.realm?.id;\n }\n\n get realmName() {\n return this.raw.data.realm?.name;\n }\n}\n\nexport function useRequestIdentity(event: IAppEvent) : RequestIdentity | undefined {\n return event.store[sym] as RequestIdentity | undefined;\n}\n\nexport function setRequestIdentity(event: IAppEvent, input: Identity | RequestIdentity) : void {\n let data : RequestIdentity;\n\n if (input instanceof RequestIdentity) {\n data = input;\n } else {\n data = new RequestIdentity(input);\n }\n\n event.store[sym] = data;\n}\n\nexport function useRequestIdentityOrFail(event: IAppEvent) : RequestIdentity {\n const identity = useRequestIdentity(event);\n if (!identity) {\n throw new UnauthorizedError();\n }\n\n return identity;\n}\n"],"mappings":";;;;;;AAYA,MAAME,MAAMC,OAAO,WAAA;AAEnB,IAAaC,kBAAb,MAAaA;CACOC;CAEhB,YAAYC,UAAoB;EAC5B,KAAKD,MAAMC;CACf;CAEA,IAAIC,WAAW;EACX,MAAM,EAAEF,QAAQ;EAChB,IAAIA,IAAIG,SAASR,aAAaS,QAC1B,OAAOJ,IAAIK,KAAKC;EAGpB,OAAON,IAAIK,KAAKE,aAAa;CACjC;CAEA,IAAIF,OAAO;EACP,OAAO,KAAKL,IAAIK;CACpB;CAEA,IAAIF,OAAO;EACP,OAAO,KAAKH,IAAIG;CACpB;CAEA,IAAIG,KAAK;EACL,OAAO,KAAKN,IAAIK,KAAKC;CACzB;CAEA,IAAIE,UAAU;EACV,OAAO,KAAKR,IAAIK,KAAKI,YAAY,KAAKT,IAAIK,KAAKK,OAAOJ;CAC1D;CAEA,IAAIK,YAAY;EACZ,OAAO,KAAKX,IAAIK,KAAKK,OAAOE;CAChC;AACJ;AAEA,SAAgBC,mBAAmBC,OAAgB;CAC/C,OAAOA,MAAMC,MAAMlB;AACvB;AAEA,SAAgBmB,mBAAmBF,OAAkBG,OAAiC;CAClF,IAAIZ;CAEJ,IAAIY,iBAAiBlB,iBACjBM,OAAOY;MAEPZ,OAAO,IAAIN,gBAAgBkB,KAAAA;CAG/BH,MAAMC,MAAMlB,OAAOQ;AACvB;AAEA,SAAgBa,yBAAyBJ,OAAgB;CACrD,MAAMb,WAAWY,mBAAmBC,KAAAA;CACpC,IAAI,CAACb,UACD,MAAM,IAAIL,kBAAAA;CAGd,OAAOK;AACX"}
|