@owlmeans/client-auth 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 +526 -0
- package/build/.gitkeep +0 -0
- package/build/components/dispatcher/component.d.ts +3 -0
- package/build/components/dispatcher/component.d.ts.map +1 -0
- package/build/components/dispatcher/component.js +70 -0
- package/build/components/dispatcher/component.js.map +1 -0
- package/build/components/dispatcher/index.d.ts +3 -0
- package/build/components/dispatcher/index.d.ts.map +1 -0
- package/build/components/dispatcher/index.js +3 -0
- package/build/components/dispatcher/index.js.map +1 -0
- package/build/components/dispatcher/types.d.ts +21 -0
- package/build/components/dispatcher/types.d.ts.map +1 -0
- package/build/components/dispatcher/types.js +2 -0
- package/build/components/dispatcher/types.js.map +1 -0
- package/build/components/index.d.ts +2 -0
- package/build/components/index.d.ts.map +1 -0
- package/build/components/index.js +2 -0
- package/build/components/index.js.map +1 -0
- package/build/consts.d.ts +4 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +4 -0
- package/build/consts.js.map +1 -0
- package/build/helper.d.ts +4 -0
- package/build/helper.d.ts.map +1 -0
- package/build/helper.js +28 -0
- package/build/helper.js.map +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/manager/components/authentication/component.d.ts +3 -0
- package/build/manager/components/authentication/component.d.ts.map +1 -0
- package/build/manager/components/authentication/component.js +28 -0
- package/build/manager/components/authentication/component.js.map +1 -0
- package/build/manager/components/authentication/consts.d.ts +2 -0
- package/build/manager/components/authentication/consts.d.ts.map +1 -0
- package/build/manager/components/authentication/consts.js +2 -0
- package/build/manager/components/authentication/consts.js.map +1 -0
- package/build/manager/components/authentication/control.d.ts +6 -0
- package/build/manager/components/authentication/control.d.ts.map +1 -0
- package/build/manager/components/authentication/control.js +146 -0
- package/build/manager/components/authentication/control.js.map +1 -0
- package/build/manager/components/authentication/index.d.ts +4 -0
- package/build/manager/components/authentication/index.d.ts.map +1 -0
- package/build/manager/components/authentication/index.js +4 -0
- package/build/manager/components/authentication/index.js.map +1 -0
- package/build/manager/components/authentication/types.d.ts +57 -0
- package/build/manager/components/authentication/types.d.ts.map +1 -0
- package/build/manager/components/authentication/types.js +2 -0
- package/build/manager/components/authentication/types.js.map +1 -0
- package/build/manager/components/index.d.ts +4 -0
- package/build/manager/components/index.d.ts.map +1 -0
- package/build/manager/components/index.js +3 -0
- package/build/manager/components/index.js.map +1 -0
- package/build/manager/components/tunnel-consumer.d.ts +4 -0
- package/build/manager/components/tunnel-consumer.d.ts.map +1 -0
- package/build/manager/components/tunnel-consumer.js +11 -0
- package/build/manager/components/tunnel-consumer.js.map +1 -0
- package/build/manager/components/types.d.ts +10 -0
- package/build/manager/components/types.d.ts.map +1 -0
- package/build/manager/components/types.js +2 -0
- package/build/manager/components/types.js.map +1 -0
- package/build/manager/errors.d.ts +6 -0
- package/build/manager/errors.d.ts.map +1 -0
- package/build/manager/errors.js +11 -0
- package/build/manager/errors.js.map +1 -0
- package/build/manager/index.d.ts +4 -0
- package/build/manager/index.d.ts.map +1 -0
- package/build/manager/index.js +4 -0
- package/build/manager/index.js.map +1 -0
- package/build/manager/modules.d.ts +2 -0
- package/build/manager/modules.d.ts.map +1 -0
- package/build/manager/modules.js +16 -0
- package/build/manager/modules.js.map +1 -0
- package/build/manager/plugins/basic-ed25519.d.ts +3 -0
- package/build/manager/plugins/basic-ed25519.d.ts.map +1 -0
- package/build/manager/plugins/basic-ed25519.js +33 -0
- package/build/manager/plugins/basic-ed25519.js.map +1 -0
- package/build/manager/plugins/exports.d.ts +6 -0
- package/build/manager/plugins/exports.d.ts.map +1 -0
- package/build/manager/plugins/exports.js +5 -0
- package/build/manager/plugins/exports.js.map +1 -0
- package/build/manager/plugins/index.d.ts +6 -0
- package/build/manager/plugins/index.d.ts.map +1 -0
- package/build/manager/plugins/index.js +9 -0
- package/build/manager/plugins/index.js.map +1 -0
- package/build/manager/plugins/re-captcha.d.ts +3 -0
- package/build/manager/plugins/re-captcha.d.ts.map +1 -0
- package/build/manager/plugins/re-captcha.js +26 -0
- package/build/manager/plugins/re-captcha.js.map +1 -0
- package/build/manager/plugins/tunnel/consts.d.ts +4 -0
- package/build/manager/plugins/tunnel/consts.d.ts.map +1 -0
- package/build/manager/plugins/tunnel/consts.js +9 -0
- package/build/manager/plugins/tunnel/consts.js.map +1 -0
- package/build/manager/plugins/tunnel/index.d.ts +4 -0
- package/build/manager/plugins/tunnel/index.d.ts.map +1 -0
- package/build/manager/plugins/tunnel/index.js +3 -0
- package/build/manager/plugins/tunnel/index.js.map +1 -0
- package/build/manager/plugins/tunnel/types.d.ts +13 -0
- package/build/manager/plugins/tunnel/types.d.ts.map +1 -0
- package/build/manager/plugins/tunnel/types.js +2 -0
- package/build/manager/plugins/tunnel/types.js.map +1 -0
- package/build/manager/plugins/tunnel/wallet.d.ts +4 -0
- package/build/manager/plugins/tunnel/wallet.d.ts.map +1 -0
- package/build/manager/plugins/tunnel/wallet.js +32 -0
- package/build/manager/plugins/tunnel/wallet.js.map +1 -0
- package/build/manager/plugins/tunnel-consumer.d.ts +3 -0
- package/build/manager/plugins/tunnel-consumer.d.ts.map +1 -0
- package/build/manager/plugins/tunnel-consumer.js +81 -0
- package/build/manager/plugins/tunnel-consumer.js.map +1 -0
- package/build/manager/plugins/types.d.ts +11 -0
- package/build/manager/plugins/types.d.ts.map +1 -0
- package/build/manager/plugins/types.js +2 -0
- package/build/manager/plugins/types.js.map +1 -0
- package/build/modules.d.ts +4 -0
- package/build/modules.d.ts.map +1 -0
- package/build/modules.js +9 -0
- package/build/modules.js.map +1 -0
- package/build/service.d.ts +6 -0
- package/build/service.d.ts.map +1 -0
- package/build/service.js +71 -0
- package/build/service.js.map +1 -0
- package/build/types.d.ts +13 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +79 -0
- package/src/components/dispatcher/component.tsx +84 -0
- package/src/components/dispatcher/index.ts +3 -0
- package/src/components/dispatcher/types.ts +24 -0
- package/src/components/index.ts +2 -0
- package/src/consts.ts +6 -0
- package/src/helper.ts +39 -0
- package/src/index.ts +7 -0
- package/src/manager/README.md +463 -0
- package/src/manager/components/authentication/component.tsx +34 -0
- package/src/manager/components/authentication/consts.ts +2 -0
- package/src/manager/components/authentication/control.ts +193 -0
- package/src/manager/components/authentication/index.ts +4 -0
- package/src/manager/components/authentication/types.ts +74 -0
- package/src/manager/components/index.ts +4 -0
- package/src/manager/components/tunnel-consumer.tsx +15 -0
- package/src/manager/components/types.ts +11 -0
- package/src/manager/errors.ts +14 -0
- package/src/manager/index.ts +4 -0
- package/src/manager/modules.ts +18 -0
- package/src/manager/plugins/basic-ed25519.tsx +42 -0
- package/src/manager/plugins/exports.ts +5 -0
- package/src/manager/plugins/index.ts +13 -0
- package/src/manager/plugins/re-captcha.tsx +31 -0
- package/src/manager/plugins/tunnel/consts.ts +12 -0
- package/src/manager/plugins/tunnel/index.ts +5 -0
- package/src/manager/plugins/tunnel/types.ts +15 -0
- package/src/manager/plugins/tunnel/wallet.ts +43 -0
- package/src/manager/plugins/tunnel-consumer.tsx +100 -0
- package/src/manager/plugins/types.ts +14 -0
- package/src/modules.ts +13 -0
- package/src/service.ts +106 -0
- package/src/types.ts +15 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
package/src/service.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { AuthServiceAppend, ClientAuthRecord } from './types.js'
|
|
2
|
+
import type { AuthService } from '@owlmeans/auth-common'
|
|
3
|
+
import { AUTH_RESOURCE, DEFAULT_ALIAS, USER_ID } from './consts.js'
|
|
4
|
+
import { assertContext, createService } from '@owlmeans/context'
|
|
5
|
+
import type { ClientContext, ClientConfig } from '@owlmeans/client-context'
|
|
6
|
+
import { AuthorizationError, DISPATCHER_AUTHEN } from '@owlmeans/auth'
|
|
7
|
+
import type { Auth, AuthToken } from '@owlmeans/auth'
|
|
8
|
+
import type { ClientModule } from '@owlmeans/client-module'
|
|
9
|
+
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope'
|
|
10
|
+
import { authMiddleware } from '@owlmeans/auth-common'
|
|
11
|
+
|
|
12
|
+
export const makeAuthService = (alias: string = DEFAULT_ALIAS): AuthService => {
|
|
13
|
+
const location = `auth-service:${alias}`
|
|
14
|
+
const service: AuthService = createService<AuthService>(alias, {
|
|
15
|
+
match: async () => service.authenticated() != null,
|
|
16
|
+
|
|
17
|
+
handle: async <T>() => {
|
|
18
|
+
return void 0 as T
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
authenticate: async token => {
|
|
22
|
+
const context = assertContext(service.ctx, location)
|
|
23
|
+
|
|
24
|
+
const [authToken] = await context.module<ClientModule<AuthToken>>(DISPATCHER_AUTHEN)
|
|
25
|
+
.call({ body: token })
|
|
26
|
+
|
|
27
|
+
await service.update(authToken.token)
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
update: async token => {
|
|
31
|
+
service.token = token
|
|
32
|
+
|
|
33
|
+
if (token == null) {
|
|
34
|
+
service.auth = undefined
|
|
35
|
+
|
|
36
|
+
const authResource = service.store<ClientAuthRecord>()
|
|
37
|
+
await authResource.delete(USER_ID)
|
|
38
|
+
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const authResource = service.store<ClientAuthRecord>()
|
|
43
|
+
await authResource.save({ id: USER_ID, token })
|
|
44
|
+
|
|
45
|
+
const [, authorization] = token.split(' ')
|
|
46
|
+
const envelope = makeEnvelopeModel<Auth>(authorization, EnvelopeKind.Token)
|
|
47
|
+
service.auth = envelope.message()
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
authenticated: async () => {
|
|
51
|
+
if (service.token == null) {
|
|
52
|
+
const authResource = service.store<ClientAuthRecord>()
|
|
53
|
+
const record = await authResource.load(USER_ID)
|
|
54
|
+
|
|
55
|
+
if (record != null) {
|
|
56
|
+
const token = record.token
|
|
57
|
+
|
|
58
|
+
if (token == '') {
|
|
59
|
+
service.token = undefined
|
|
60
|
+
service.auth = undefined
|
|
61
|
+
await authResource.delete(USER_ID)
|
|
62
|
+
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const [, authorization] = token.split(' ')
|
|
67
|
+
service.token = token
|
|
68
|
+
|
|
69
|
+
const envelope = makeEnvelopeModel<Auth>(authorization, EnvelopeKind.Token)
|
|
70
|
+
|
|
71
|
+
service.auth = envelope.message()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return service.token ?? null
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
user: () => {
|
|
79
|
+
if (service.auth == null) {
|
|
80
|
+
throw new AuthorizationError()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return service.auth
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
store: () => service.assertCtx(location).resource(AUTH_RESOURCE)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
return service
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const appendAuthService = <C extends ClientConfig, T extends ClientContext<C>>(
|
|
93
|
+
ctx: T, alias: string = DEFAULT_ALIAS
|
|
94
|
+
): T & AuthServiceAppend => {
|
|
95
|
+
const service = makeAuthService(alias)
|
|
96
|
+
|
|
97
|
+
const context = ctx as T & AuthServiceAppend
|
|
98
|
+
|
|
99
|
+
context.registerService(service)
|
|
100
|
+
|
|
101
|
+
context.registerMiddleware(authMiddleware)
|
|
102
|
+
|
|
103
|
+
context.auth = () => ctx.service(service.alias)
|
|
104
|
+
|
|
105
|
+
return context
|
|
106
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ClientResource } from '@owlmeans/client-resource'
|
|
2
|
+
import type { ResourceRecord } from '@owlmeans/resource'
|
|
3
|
+
import type { AuthService } from '@owlmeans/auth-common'
|
|
4
|
+
|
|
5
|
+
export interface AuthServiceAppend {
|
|
6
|
+
auth: () => AuthService
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ClientAuthRecord extends ResourceRecord {
|
|
10
|
+
token: string
|
|
11
|
+
profileId?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ClientAuthResource extends ClientResource<ClientAuthRecord> {
|
|
15
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"../tsconfig.default.json",
|
|
4
|
+
"../tsconfig.react.json",
|
|
5
|
+
],
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"rootDir": "./src/", /* Specify the root folder within your source files. */
|
|
8
|
+
"outDir": "./build/", /* Specify an output folder for all emitted files. */
|
|
9
|
+
},
|
|
10
|
+
"exclude": [
|
|
11
|
+
"./dist/**/*",
|
|
12
|
+
"./build/**/*",
|
|
13
|
+
"./*.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/consts.ts","./src/helper.ts","./src/index.ts","./src/modules.ts","./src/service.ts","./src/types.ts","./src/components/index.ts","./src/components/dispatcher/component.tsx","./src/components/dispatcher/index.ts","./src/components/dispatcher/types.ts","./src/manager/errors.ts","./src/manager/index.ts","./src/manager/modules.ts","./src/manager/components/index.ts","./src/manager/components/tunnel-consumer.tsx","./src/manager/components/types.ts","./src/manager/components/authentication/component.tsx","./src/manager/components/authentication/consts.ts","./src/manager/components/authentication/control.ts","./src/manager/components/authentication/index.ts","./src/manager/components/authentication/types.ts","./src/manager/plugins/basic-ed25519.tsx","./src/manager/plugins/exports.ts","./src/manager/plugins/index.ts","./src/manager/plugins/re-captcha.tsx","./src/manager/plugins/tunnel-consumer.tsx","./src/manager/plugins/types.ts","./src/manager/plugins/tunnel/consts.ts","./src/manager/plugins/tunnel/index.ts","./src/manager/plugins/tunnel/types.ts","./src/manager/plugins/tunnel/wallet.ts"],"version":"5.6.3"}
|