@owlmeans/server-oidc-provider 0.1.0
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/LICENSE +21 -0
- package/README.md +848 -0
- package/build/.gitkeep +0 -0
- package/build/consts.d.ts +3 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +3 -0
- package/build/consts.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/build/middleware.d.ts +3 -0
- package/build/middleware.d.ts.map +1 -0
- package/build/middleware.js +24 -0
- package/build/middleware.js.map +1 -0
- package/build/service.d.ts +4 -0
- package/build/service.d.ts.map +1 -0
- package/build/service.js +78 -0
- package/build/service.js.map +1 -0
- package/build/types.d.ts +46 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/build/utils/client.d.ts +4 -0
- package/build/utils/client.d.ts.map +1 -0
- package/build/utils/client.js +31 -0
- package/build/utils/client.js.map +1 -0
- package/build/utils/config.d.ts +4 -0
- package/build/utils/config.d.ts.map +1 -0
- package/build/utils/config.js +39 -0
- package/build/utils/config.js.map +1 -0
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +3 -0
- package/build/utils/index.js.map +1 -0
- package/package.json +49 -0
- package/src/consts.ts +4 -0
- package/src/index.ts +5 -0
- package/src/middleware.ts +29 -0
- package/src/service.ts +103 -0
- package/src/types.ts +55 -0
- package/src/utils/client.ts +40 -0
- package/src/utils/config.ts +43 -0
- package/src/utils/index.ts +3 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { randomBytes } from '@noble/hashes/utils'
|
|
2
|
+
import { hex } from '@scure/base'
|
|
3
|
+
import type { ClientMetadata } from 'oidc-provider'
|
|
4
|
+
import type { Config, Context } from '../types.js'
|
|
5
|
+
import { makeSecurityHelper } from '@owlmeans/config'
|
|
6
|
+
import type { SecurityHelper } from '@owlmeans/config'
|
|
7
|
+
import { SEP } from '@owlmeans/route'
|
|
8
|
+
|
|
9
|
+
export const updateClient = (context: Context, client: ClientMetadata): ClientMetadata => {
|
|
10
|
+
if (client.client_secret == null) {
|
|
11
|
+
if (!context.cfg.debug.all && !context.cfg.debug.oidc) {
|
|
12
|
+
throw new SyntaxError('Client secret is required')
|
|
13
|
+
}
|
|
14
|
+
client.client_secret = hex.encode(randomBytes(32))
|
|
15
|
+
|
|
16
|
+
console.info('\n')
|
|
17
|
+
console.info('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
|
|
18
|
+
console.warn('IT IS EXCEPTIONALY UNSECURE, BUT WE GENEREATED A CLIENT SECRET FOR YOU', client.client_secret)
|
|
19
|
+
console.info('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
|
|
20
|
+
console.info('\n')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const helper = makeSecurityHelper<Config, Context>(context)
|
|
24
|
+
const updateUri = makeUriUpdater(context, helper)
|
|
25
|
+
client.redirect_uris = client.redirect_uris?.map(updateUri) ?? []
|
|
26
|
+
client.post_logout_redirect_uris = client.post_logout_redirect_uris?.map(updateUri) ?? []
|
|
27
|
+
|
|
28
|
+
return client
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const makeUriUpdater = (context: Context, helper: SecurityHelper) => (uri: string): string => {
|
|
32
|
+
if (uri.startsWith('{{')) {
|
|
33
|
+
const [host, ...parts] = uri.split(SEP)
|
|
34
|
+
|
|
35
|
+
const service = context.cfg.services[host.slice(2, -2)]
|
|
36
|
+
return helper.makeUrl(service, parts.join(SEP))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return uri
|
|
40
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Context } from '../types.js'
|
|
2
|
+
import type { Configuration } from 'oidc-provider'
|
|
3
|
+
import { updateClient } from './client.js'
|
|
4
|
+
import * as jose from 'jose'
|
|
5
|
+
|
|
6
|
+
export const combineConfig = async (context: Context, _unsecure: boolean): Promise<Configuration> => {
|
|
7
|
+
const cfg = context.cfg.oidc
|
|
8
|
+
|
|
9
|
+
const configuration: Configuration = {
|
|
10
|
+
...cfg.customConfiguration,
|
|
11
|
+
clients: [
|
|
12
|
+
...cfg.clients,
|
|
13
|
+
...(cfg.customConfiguration?.clients ?? [])
|
|
14
|
+
].map(client => updateClient(context, client)),
|
|
15
|
+
claims: {
|
|
16
|
+
email: ['email', 'email_verified', ...cfg.customConfiguration?.claims?.email ?? []],
|
|
17
|
+
profile: [
|
|
18
|
+
'username', 'family_name', 'given_name', 'locale', 'name', 'nickname', 'preferred_username',
|
|
19
|
+
...cfg.customConfiguration?.claims?.profile ?? []
|
|
20
|
+
],
|
|
21
|
+
...cfg.customConfiguration?.claims,
|
|
22
|
+
},
|
|
23
|
+
scopes: ['openid', 'profile', 'offline_access', ...cfg.customConfiguration?.scopes ?? []],
|
|
24
|
+
features: {
|
|
25
|
+
...cfg.customConfiguration?.features,
|
|
26
|
+
devInteractions: { enabled: false }
|
|
27
|
+
// devInteractions: {
|
|
28
|
+
// enabled: (
|
|
29
|
+
// (context.cfg.debug.all && context.cfg.debug.oidc !== false)
|
|
30
|
+
// || context.cfg.debug.oidc
|
|
31
|
+
// ) && unsecure,
|
|
32
|
+
// ...cfg.customConfiguration?.features?.devInteractions,
|
|
33
|
+
// },
|
|
34
|
+
},
|
|
35
|
+
jwks: {
|
|
36
|
+
keys: [
|
|
37
|
+
await jose.exportJWK(await jose.importPKCS8(cfg.defaultKeys.RS256.pk, 'RS256'))
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return configuration
|
|
43
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"../tsconfig.default.json",
|
|
4
|
+
],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"rootDir": "./src/", /* Specify the root folder within your source files. */
|
|
7
|
+
"outDir": "./build/", /* Specify an output folder for all emitted files. */
|
|
8
|
+
"moduleResolution": "Bundler",
|
|
9
|
+
},
|
|
10
|
+
"exclude": [
|
|
11
|
+
"./dist/**/*",
|
|
12
|
+
"./build/**/*",
|
|
13
|
+
"./*.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|