@things-factory/auth-base 5.0.7 → 5.0.11
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/config/config.development.js +2 -1
- package/dist-server/constants/error-code.js.map +1 -1
- package/dist-server/constants/error-message.js.map +1 -1
- package/dist-server/constants/max-age.js.map +1 -1
- package/dist-server/controllers/auth.js +5 -18
- package/dist-server/controllers/auth.js.map +1 -1
- package/dist-server/controllers/change-pwd.js +6 -8
- package/dist-server/controllers/change-pwd.js.map +1 -1
- package/dist-server/controllers/checkin.js.map +1 -1
- package/dist-server/controllers/delete-user.js.map +1 -1
- package/dist-server/controllers/invitation.js +3 -8
- package/dist-server/controllers/invitation.js.map +1 -1
- package/dist-server/controllers/profile.js.map +1 -1
- package/dist-server/controllers/reset-password.js +7 -9
- package/dist-server/controllers/reset-password.js.map +1 -1
- package/dist-server/controllers/signin.js.map +1 -1
- package/dist-server/controllers/signup.js.map +1 -1
- package/dist-server/controllers/unlock-user.js.map +1 -1
- package/dist-server/controllers/utils/make-invitation-token.js +2 -4
- package/dist-server/controllers/utils/make-invitation-token.js.map +1 -1
- package/dist-server/controllers/utils/make-verification-token.js +2 -4
- package/dist-server/controllers/utils/make-verification-token.js.map +1 -1
- package/dist-server/controllers/utils/password-rule.js +2 -5
- package/dist-server/controllers/utils/password-rule.js.map +1 -1
- package/dist-server/controllers/utils/save-invitation-token.js.map +1 -1
- package/dist-server/controllers/utils/save-verification-token.js.map +1 -1
- package/dist-server/controllers/verification.js.map +1 -1
- package/dist-server/errors/auth-error.js +2 -24
- package/dist-server/errors/auth-error.js.map +1 -1
- package/dist-server/errors/index.js +3 -16
- package/dist-server/errors/index.js.map +1 -1
- package/dist-server/errors/user-domain-not-match-error.js.map +1 -1
- package/dist-server/index.js +12 -25
- package/dist-server/index.js.map +1 -1
- package/dist-server/middlewares/authenticate-401-middleware.js +0 -6
- package/dist-server/middlewares/authenticate-401-middleware.js.map +1 -1
- package/dist-server/middlewares/domain-authenticate-middleware.js +2 -5
- package/dist-server/middlewares/domain-authenticate-middleware.js.map +1 -1
- package/dist-server/middlewares/graphql-authenticate-middleware.js +1 -3
- package/dist-server/middlewares/graphql-authenticate-middleware.js.map +1 -1
- package/dist-server/middlewares/index.js +6 -24
- package/dist-server/middlewares/index.js.map +1 -1
- package/dist-server/middlewares/jwt-authenticate-middleware.js +5 -11
- package/dist-server/middlewares/jwt-authenticate-middleware.js.map +1 -1
- package/dist-server/middlewares/signin-middleware.js +2 -6
- package/dist-server/middlewares/signin-middleware.js.map +1 -1
- package/dist-server/migrations/1548206416130-SeedUser.js.map +1 -1
- package/dist-server/migrations/1566805283882-SeedPrivilege.js.map +1 -1
- package/dist-server/migrations/index.js.map +1 -1
- package/dist-server/router/auth-checkin-router.js +3 -8
- package/dist-server/router/auth-checkin-router.js.map +1 -1
- package/dist-server/router/auth-private-process-router.js +15 -20
- package/dist-server/router/auth-private-process-router.js.map +1 -1
- package/dist-server/router/auth-public-process-router.js +4 -22
- package/dist-server/router/auth-public-process-router.js.map +1 -1
- package/dist-server/router/auth-signin-router.js +2 -7
- package/dist-server/router/auth-signin-router.js.map +1 -1
- package/dist-server/router/auth-signup-router.js +3 -8
- package/dist-server/router/auth-signup-router.js.map +1 -1
- package/dist-server/router/index.js +9 -22
- package/dist-server/router/index.js.map +1 -1
- package/dist-server/router/oauth2/index.js +3 -16
- package/dist-server/router/oauth2/index.js.map +1 -1
- package/dist-server/router/oauth2/oauth2-authorize-router.js +2 -9
- package/dist-server/router/oauth2/oauth2-authorize-router.js.map +1 -1
- package/dist-server/router/oauth2/oauth2-router.js +5 -10
- package/dist-server/router/oauth2/oauth2-router.js.map +1 -1
- package/dist-server/router/oauth2/oauth2-server.js +2 -14
- package/dist-server/router/oauth2/oauth2-server.js.map +1 -1
- package/dist-server/router/oauth2/passport-oauth2-client-password.js +3 -5
- package/dist-server/router/oauth2/passport-oauth2-client-password.js.map +1 -1
- package/dist-server/router/oauth2/passport-refresh-token.js +3 -5
- package/dist-server/router/oauth2/passport-refresh-token.js.map +1 -1
- package/dist-server/router/path-base-domain-router.js +2 -6
- package/dist-server/router/path-base-domain-router.js.map +1 -1
- package/dist-server/router/site-root-router.js +4 -13
- package/dist-server/router/site-root-router.js.map +1 -1
- package/dist-server/routes.js +2 -9
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/app-binding/app-binding-mutation.js +10 -23
- package/dist-server/service/app-binding/app-binding-mutation.js.map +1 -1
- package/dist-server/service/app-binding/app-binding-query.js +45 -52
- package/dist-server/service/app-binding/app-binding-query.js.map +1 -1
- package/dist-server/service/app-binding/app-binding-types.js +6 -14
- package/dist-server/service/app-binding/app-binding-types.js.map +1 -1
- package/dist-server/service/app-binding/app-binding.js +8 -16
- package/dist-server/service/app-binding/app-binding.js.map +1 -1
- package/dist-server/service/app-binding/index.js.map +1 -1
- package/dist-server/service/appliance/appliance-mutation.js +27 -41
- package/dist-server/service/appliance/appliance-mutation.js.map +1 -1
- package/dist-server/service/appliance/appliance-query.js +29 -40
- package/dist-server/service/appliance/appliance-query.js.map +1 -1
- package/dist-server/service/appliance/appliance-types.js +34 -42
- package/dist-server/service/appliance/appliance-types.js.map +1 -1
- package/dist-server/service/appliance/appliance.js +35 -46
- package/dist-server/service/appliance/appliance.js.map +1 -1
- package/dist-server/service/appliance/index.js.map +1 -1
- package/dist-server/service/application/application-mutation.js +34 -48
- package/dist-server/service/application/application-mutation.js.map +1 -1
- package/dist-server/service/application/application-query.js +44 -55
- package/dist-server/service/application/application-query.js.map +1 -1
- package/dist-server/service/application/application-types.js +41 -49
- package/dist-server/service/application/application-types.js.map +1 -1
- package/dist-server/service/application/application.js +42 -53
- package/dist-server/service/application/application.js.map +1 -1
- package/dist-server/service/application/index.js.map +1 -1
- package/dist-server/service/domain-generator/domain-generator-mutation.js +14 -25
- package/dist-server/service/domain-generator/domain-generator-mutation.js.map +1 -1
- package/dist-server/service/domain-generator/domain-generator-types.js +26 -34
- package/dist-server/service/domain-generator/domain-generator-types.js.map +1 -1
- package/dist-server/service/domain-generator/index.js.map +1 -1
- package/dist-server/service/granted-role/granted-role-mutation.js +9 -20
- package/dist-server/service/granted-role/granted-role-mutation.js.map +1 -1
- package/dist-server/service/granted-role/granted-role-query.js +23 -34
- package/dist-server/service/granted-role/granted-role-query.js.map +1 -1
- package/dist-server/service/granted-role/granted-role.js +12 -20
- package/dist-server/service/granted-role/granted-role.js.map +1 -1
- package/dist-server/service/granted-role/index.js.map +1 -1
- package/dist-server/service/index.js +22 -35
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/invitation/index.js.map +1 -1
- package/dist-server/service/invitation/invitation-mutation.js +17 -28
- package/dist-server/service/invitation/invitation-mutation.js.map +1 -1
- package/dist-server/service/invitation/invitation-query.js +15 -26
- package/dist-server/service/invitation/invitation-query.js.map +1 -1
- package/dist-server/service/invitation/invitation-types.js +6 -14
- package/dist-server/service/invitation/invitation-types.js.map +1 -1
- package/dist-server/service/invitation/invitation.js +24 -32
- package/dist-server/service/invitation/invitation.js.map +1 -1
- package/dist-server/service/login-history/index.js.map +1 -1
- package/dist-server/service/login-history/login-history-query.js +18 -29
- package/dist-server/service/login-history/login-history-query.js.map +1 -1
- package/dist-server/service/login-history/login-history.js +16 -24
- package/dist-server/service/login-history/login-history.js.map +1 -1
- package/dist-server/service/partner/index.js.map +1 -1
- package/dist-server/service/partner/partner-mutation.js +14 -25
- package/dist-server/service/partner/partner-mutation.js.map +1 -1
- package/dist-server/service/partner/partner-query.js +44 -55
- package/dist-server/service/partner/partner-query.js.map +1 -1
- package/dist-server/service/partner/partner-types.js +6 -14
- package/dist-server/service/partner/partner-types.js.map +1 -1
- package/dist-server/service/partner/partner.js +24 -32
- package/dist-server/service/partner/partner.js.map +1 -1
- package/dist-server/service/password-history/index.js.map +1 -1
- package/dist-server/service/password-history/password-history.js +6 -14
- package/dist-server/service/password-history/password-history.js.map +1 -1
- package/dist-server/service/privilege/index.js.map +1 -1
- package/dist-server/service/privilege/privilege-directive.js +2 -5
- package/dist-server/service/privilege/privilege-directive.js.map +1 -1
- package/dist-server/service/privilege/privilege-mutation.js +26 -37
- package/dist-server/service/privilege/privilege-mutation.js.map +1 -1
- package/dist-server/service/privilege/privilege-query.js +35 -46
- package/dist-server/service/privilege/privilege-query.js.map +1 -1
- package/dist-server/service/privilege/privilege-types.js +35 -43
- package/dist-server/service/privilege/privilege-types.js.map +1 -1
- package/dist-server/service/privilege/privilege.js +24 -32
- package/dist-server/service/privilege/privilege.js.map +1 -1
- package/dist-server/service/role/index.js.map +1 -1
- package/dist-server/service/role/role-mutation.js +27 -38
- package/dist-server/service/role/role-mutation.js.map +1 -1
- package/dist-server/service/role/role-query.js +61 -72
- package/dist-server/service/role/role-query.js.map +1 -1
- package/dist-server/service/role/role-types.js +48 -56
- package/dist-server/service/role/role-types.js.map +1 -1
- package/dist-server/service/role/role.js +28 -36
- package/dist-server/service/role/role.js.map +1 -1
- package/dist-server/service/user/index.js.map +1 -1
- package/dist-server/service/user/user-mutation.js +65 -76
- package/dist-server/service/user/user-mutation.js.map +1 -1
- package/dist-server/service/user/user-query.js +59 -70
- package/dist-server/service/user/user-query.js.map +1 -1
- package/dist-server/service/user/user-types.js +40 -48
- package/dist-server/service/user/user-types.js.map +1 -1
- package/dist-server/service/user/user.js +46 -57
- package/dist-server/service/user/user.js.map +1 -1
- package/dist-server/service/verification-token/index.js.map +1 -1
- package/dist-server/service/verification-token/verification-token.js +14 -22
- package/dist-server/service/verification-token/verification-token.js.map +1 -1
- package/dist-server/templates/account-unlock-email.js.map +1 -1
- package/dist-server/templates/invitation-email.js.map +1 -1
- package/dist-server/templates/reset-password-email.js.map +1 -1
- package/dist-server/templates/verification-email.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/dist-server/utils/accepts.js.map +1 -1
- package/dist-server/utils/access-token-cookie.js.map +1 -1
- package/dist-server/utils/check-user-belongs-domain.js.map +1 -1
- package/dist-server/utils/get-domain-from-hostname.js.map +1 -1
- package/dist-server/utils/get-domain-users.js.map +1 -1
- package/dist-server/utils/get-secret.js.map +1 -1
- package/dist-server/utils/get-user-domains.js.map +1 -1
- package/package.json +5 -5
- package/server/controllers/change-pwd.ts +10 -13
- package/server/controllers/invitation.ts +5 -10
- package/server/controllers/reset-password.ts +10 -11
- package/server/controllers/utils/password-rule.ts +0 -1
- package/server/middlewares/authenticate-401-middleware.ts +0 -8
- package/server/middlewares/domain-authenticate-middleware.ts +4 -8
- package/server/middlewares/graphql-authenticate-middleware.ts +1 -5
- package/server/middlewares/index.ts +0 -4
- package/server/middlewares/jwt-authenticate-middleware.ts +4 -9
- package/server/middlewares/signin-middleware.ts +6 -5
- package/server/router/auth-checkin-router.ts +4 -6
- package/server/router/auth-private-process-router.ts +16 -17
- package/server/router/auth-public-process-router.ts +4 -34
- package/server/router/auth-signin-router.ts +1 -5
- package/server/router/auth-signup-router.ts +3 -10
- package/server/router/oauth2/oauth2-authorize-router.ts +1 -8
- package/server/router/oauth2/oauth2-router.ts +0 -6
- package/server/router/oauth2/oauth2-server.ts +0 -12
- package/server/router/path-base-domain-router.ts +0 -4
- package/server/router/site-root-router.ts +4 -11
- package/server/routes.ts +8 -13
- package/server/service/app-binding/app-binding-mutation.ts +3 -6
- package/server/service/app-binding/app-binding-query.ts +7 -6
- package/server/service/appliance/appliance-mutation.ts +0 -5
- package/server/service/application/application-mutation.ts +3 -6
- package/server/service/granted-role/granted-role-mutation.ts +1 -1
- package/server/service/privilege/privilege-directive.ts +0 -2
- package/server/service/privilege/privilege-mutation.ts +5 -4
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import { getRepository } from 'typeorm'
|
|
3
|
+
|
|
3
4
|
import { Application } from '../../service/application/application'
|
|
4
5
|
import { NonClient, server as oauth2orizeServer } from './oauth2-server'
|
|
5
6
|
|
|
6
|
-
const debug = require('debug')('things-factory:auth-base:oauth2-authorize-router')
|
|
7
|
-
|
|
8
7
|
export const oauth2AuthorizeRouter = new Router()
|
|
9
8
|
|
|
10
9
|
// user authorization endpoint
|
|
@@ -34,8 +33,6 @@ oauth2AuthorizeRouter.get(
|
|
|
34
33
|
// return false
|
|
35
34
|
// }
|
|
36
35
|
|
|
37
|
-
debug('authorize fetch client', clientID, redirectURI, client)
|
|
38
|
-
|
|
39
36
|
return [client || NonClient, redirectURI]
|
|
40
37
|
}),
|
|
41
38
|
async function (context, next) {
|
|
@@ -45,13 +42,10 @@ oauth2AuthorizeRouter.get(
|
|
|
45
42
|
let elementScript: string = '/oauth2/oauth2-decision-page.js'
|
|
46
43
|
|
|
47
44
|
if (oauth2.client.id === NonClient.id) {
|
|
48
|
-
debug('authorize client not found : will render not found error in the decision page')
|
|
49
45
|
pageElement = 'oauth2-decision-error'
|
|
50
46
|
elementScript = '/oauth2/oauth2-decision-error-page.js'
|
|
51
47
|
}
|
|
52
48
|
|
|
53
|
-
debug('authorize render page', oauth2)
|
|
54
|
-
|
|
55
49
|
try {
|
|
56
50
|
await context.render('oauth2-page', {
|
|
57
51
|
pageElement,
|
|
@@ -74,7 +68,6 @@ oauth2AuthorizeRouter.get(
|
|
|
74
68
|
// availableScopes
|
|
75
69
|
// })
|
|
76
70
|
} catch (e) {
|
|
77
|
-
debug('render decision page error', e)
|
|
78
71
|
throw e
|
|
79
72
|
}
|
|
80
73
|
}
|
|
@@ -22,15 +22,11 @@ declare global {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const debug = require('debug')('things-factory:auth-base:oauth2-router')
|
|
26
|
-
|
|
27
25
|
export const oauth2Router = new Router()
|
|
28
26
|
|
|
29
27
|
passport.use(
|
|
30
28
|
'oauth2-client-password',
|
|
31
29
|
new ClientPasswordStrategy({}, (clientId, clientSecret, done) => {
|
|
32
|
-
debug('oauth2-client-password', clientId, clientSecret)
|
|
33
|
-
|
|
34
30
|
getRepository(Application)
|
|
35
31
|
.findOne({
|
|
36
32
|
appKey: clientId
|
|
@@ -122,8 +118,6 @@ oauth2Router.post('/refresh-token', async (context, next) => {
|
|
|
122
118
|
oauth2Router.get('/profile', jwtAuthenticateMiddleware, async (context, next) => {
|
|
123
119
|
const { user, domain } = context.state
|
|
124
120
|
|
|
125
|
-
debug('getting user/application profile', user, domain)
|
|
126
|
-
|
|
127
121
|
const { name, description, email, userType: type, locale } = user
|
|
128
122
|
const { name: domainName, subdomain, brandName, brandImage, contentImage, timezone } = domain || {}
|
|
129
123
|
|
|
@@ -9,7 +9,6 @@ import { Role } from '../../service/role/role'
|
|
|
9
9
|
import { User, UserStatus } from '../../service/user/user'
|
|
10
10
|
|
|
11
11
|
const crypto = require('crypto')
|
|
12
|
-
const debug = require('debug')('things-factory:auth-base:oauth2-server')
|
|
13
12
|
|
|
14
13
|
export const NOTFOUND = 'NOTFOUND'
|
|
15
14
|
export const NonClient = {
|
|
@@ -33,18 +32,15 @@ export const server = oauth2orize.createServer()
|
|
|
33
32
|
// the client by ID from the database.
|
|
34
33
|
|
|
35
34
|
server.serializeClient(async function (client) {
|
|
36
|
-
debug('serialze', client)
|
|
37
35
|
return client.id
|
|
38
36
|
})
|
|
39
37
|
|
|
40
38
|
server.deserializeClient(async function (id) {
|
|
41
39
|
if (id == NOTFOUND) {
|
|
42
|
-
debug('deserialize - not found')
|
|
43
40
|
return {}
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
const application = await getRepository(Application).findOne(id)
|
|
47
|
-
debug('deserialize', id, application)
|
|
48
44
|
return application
|
|
49
45
|
})
|
|
50
46
|
|
|
@@ -81,9 +77,7 @@ server.exchange(
|
|
|
81
77
|
try {
|
|
82
78
|
/* authorization code */
|
|
83
79
|
var decoded: any = Application.verifyAuthCode(code)
|
|
84
|
-
debug('exchange code - decoded', decoded)
|
|
85
80
|
} catch (e) {
|
|
86
|
-
debug('exchange code', e)
|
|
87
81
|
return false
|
|
88
82
|
}
|
|
89
83
|
let { email, appKey, subdomain, scopes } = decoded
|
|
@@ -93,12 +87,9 @@ server.exchange(
|
|
|
93
87
|
})
|
|
94
88
|
|
|
95
89
|
if (!application) {
|
|
96
|
-
debug('exchange code', 'application is not exist')
|
|
97
90
|
return false
|
|
98
91
|
}
|
|
99
92
|
|
|
100
|
-
debug('exchange code - application', application)
|
|
101
|
-
|
|
102
93
|
/* DONT-FORGET uncomment after test */
|
|
103
94
|
// if (redirectUrl !== application.redirectUrl && redirectUrl.indexOf(application.redirectUrl) != 0) {
|
|
104
95
|
// logger.error(
|
|
@@ -179,7 +170,6 @@ server.exchange(
|
|
|
179
170
|
try {
|
|
180
171
|
/* refresh token */
|
|
181
172
|
var decoded: any = Application.verifyAuthCode(refreshToken)
|
|
182
|
-
debug('exchange refresh-token - decoded', decoded)
|
|
183
173
|
} catch (e) {
|
|
184
174
|
logger.error(e)
|
|
185
175
|
return false
|
|
@@ -203,8 +193,6 @@ server.exchange(
|
|
|
203
193
|
return false
|
|
204
194
|
}
|
|
205
195
|
|
|
206
|
-
debug('exchange refresh-token - application', application?.name)
|
|
207
|
-
|
|
208
196
|
if (Date.now() > expires_in * 1000) {
|
|
209
197
|
logger.error('refresh token is expired')
|
|
210
198
|
return false
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
|
|
3
|
-
const debug = require('debug')('things-factory:auth-base:path-base-domain-router')
|
|
4
|
-
|
|
5
3
|
export const pathBaseDomainRouter = new Router()
|
|
6
4
|
|
|
7
5
|
/* browser history fallback 을 위한 라우터. */
|
|
8
6
|
pathBaseDomainRouter.get('/(.*)', async (context, next) => {
|
|
9
|
-
debug('get:/(.*)', context.path)
|
|
10
|
-
|
|
11
7
|
await next()
|
|
12
8
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Domain, domainMiddleware } from '@things-factory/shell'
|
|
2
1
|
import Router from 'koa-router'
|
|
3
2
|
import passport from 'passport'
|
|
3
|
+
|
|
4
|
+
import { Domain, domainMiddleware } from '@things-factory/shell'
|
|
5
|
+
|
|
4
6
|
import { User } from '../service/user/user'
|
|
5
7
|
import { getUserDomains } from '../utils/get-user-domains'
|
|
6
8
|
|
|
7
|
-
const debug = require('debug')('things-factory:auth-base:site-root-router')
|
|
8
|
-
|
|
9
9
|
export const siteRootRouter = new Router()
|
|
10
10
|
|
|
11
11
|
async function findAuth(context, next) {
|
|
@@ -14,9 +14,7 @@ async function findAuth(context, next) {
|
|
|
14
14
|
try {
|
|
15
15
|
const user = await User.checkAuth(decoded)
|
|
16
16
|
context.state.user = user
|
|
17
|
-
} catch (e) {
|
|
18
|
-
debug('not signed in', e)
|
|
19
|
-
}
|
|
17
|
+
} catch (e) {}
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
await next()
|
|
@@ -25,24 +23,19 @@ async function findAuth(context, next) {
|
|
|
25
23
|
|
|
26
24
|
siteRootRouter.get('/', findAuth, domainMiddleware, async (context, next) => {
|
|
27
25
|
const { user, domain } = context.state
|
|
28
|
-
debug('get:/', user?.email, domain?.subdomain)
|
|
29
26
|
|
|
30
27
|
const subdomain = domain?.subdomain
|
|
31
28
|
|
|
32
29
|
if (user && subdomain) {
|
|
33
30
|
const userDomains: Domain[] = await getUserDomains(user)
|
|
34
31
|
if (userDomains.find(userDomain => userDomain.subdomain == subdomain)) {
|
|
35
|
-
debug('get:/', user.email, subdomain, 'user have access right to the subdomain. so, redirect to business-home')
|
|
36
32
|
return await next()
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
debug('get:/', user.email, subdomain, "user doesn't have access right to the subdomain. so, redirect to checkin")
|
|
40
|
-
|
|
41
35
|
return context.redirect(`/auth/checkin/${subdomain}`)
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
if (user && !subdomain) {
|
|
45
|
-
debug('get:/', user?.email, 'redirect to checkin')
|
|
46
39
|
context.redirect('/auth/checkin')
|
|
47
40
|
|
|
48
41
|
return
|
package/server/routes.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
+
import session from 'koa-session'
|
|
2
|
+
|
|
1
3
|
import { config } from '@things-factory/env'
|
|
4
|
+
|
|
2
5
|
import { domainAuthenticateMiddleware, jwtAuthenticateMiddleware } from './middlewares'
|
|
3
6
|
import {
|
|
4
|
-
|
|
7
|
+
authCheckinRouter,
|
|
5
8
|
authPrivateProcessRouter,
|
|
6
9
|
authPublicProcessRouter,
|
|
7
10
|
authSigninRouter,
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
authSignupRouter,
|
|
12
|
+
oauth2AuthorizeRouter,
|
|
10
13
|
oauth2Router,
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
pathBaseDomainRouter,
|
|
15
|
+
siteRootRouter
|
|
13
16
|
} from './router'
|
|
14
|
-
import session from 'koa-session'
|
|
15
17
|
import { SECRET } from './utils/get-secret'
|
|
16
18
|
|
|
17
19
|
const isPathBaseDomain = !config.get('subdomain') && !config.get('useVirtualHostBasedDomain')
|
|
18
|
-
const debug = require('debug')('things-factory:auth-base:routes')
|
|
19
20
|
|
|
20
21
|
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
21
|
-
debug('bootstrap-module-global-public-route')
|
|
22
|
-
|
|
23
22
|
globalPublicRouter.use(siteRootRouter.routes(), siteRootRouter.allowedMethods())
|
|
24
23
|
globalPublicRouter.use(authPublicProcessRouter.routes(), authPublicProcessRouter.allowedMethods())
|
|
25
24
|
})
|
|
@@ -33,8 +32,6 @@ process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRo
|
|
|
33
32
|
})
|
|
34
33
|
|
|
35
34
|
process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
|
|
36
|
-
debug('bootstrap-module-domain-public-route')
|
|
37
|
-
|
|
38
35
|
/* domainPublicRouter based nested-routers */
|
|
39
36
|
domainPublicRouter.use(authSigninRouter.routes(), authSigninRouter.allowedMethods())
|
|
40
37
|
domainPublicRouter.use(authSignupRouter.routes(), authSignupRouter.allowedMethods())
|
|
@@ -71,8 +68,6 @@ process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRo
|
|
|
71
68
|
// '(.[^.]+)' 은 '', '/'는 제외하고, '/xxx', '/yyy/zzz' 등 모두를 포함하지만, path에 '.'가 있는 경우는 제외한다.
|
|
72
69
|
// (테스트는 여기서 : http://forbeslindesay.github.io/express-route-tester/)
|
|
73
70
|
domainPrivateRouter.get('(.[^.]+)', async (context, next) => {
|
|
74
|
-
const { path } = context
|
|
75
|
-
debug('get:(.[^.]+)', path)
|
|
76
71
|
await next()
|
|
77
72
|
})
|
|
78
73
|
})
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Resolver, Mutation, Arg, Ctx } from 'type-graphql'
|
|
3
|
-
import { User } from '../user/user'
|
|
1
|
+
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
|
4
2
|
import { getRepository } from 'typeorm'
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
import { User } from '../user/user'
|
|
5
|
+
import { AppBinding } from './app-binding'
|
|
7
6
|
|
|
8
7
|
@Resolver(AppBinding)
|
|
9
8
|
export class AppBindingMutation {
|
|
@@ -11,8 +10,6 @@ export class AppBindingMutation {
|
|
|
11
10
|
async deleteAppBinding(@Arg('id') id: string, @Ctx() context: any) {
|
|
12
11
|
const { domain } = context.state
|
|
13
12
|
|
|
14
|
-
debug('user', id)
|
|
15
|
-
|
|
16
13
|
// TODO 이 사용자가 이 도메인에 속한 사용자인지 확인해야함.
|
|
17
14
|
// TODO 다른 도메인에도 포함되어있다면, domains-users 관게와 해당 도메인 관련 정보만 삭제해야 함.
|
|
18
15
|
await getRepository(User).delete({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
2
|
import { getRepository, SelectQueryBuilder } from 'typeorm'
|
|
3
3
|
|
|
4
|
-
import { buildQuery,
|
|
4
|
+
import { buildQuery, ListParam } from '@things-factory/shell'
|
|
5
5
|
|
|
6
6
|
import { buildDomainUsersQueryBuilder } from '../../utils/get-domain-users'
|
|
7
7
|
import { Application } from '../application/application'
|
|
@@ -20,15 +20,16 @@ export class AppBindingQuery {
|
|
|
20
20
|
return await getRepository(User).findOne({ id, userType: 'application' })
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/* TODO optimize query */
|
|
23
24
|
@Query(returns => AppBindingList)
|
|
24
25
|
async appBindings(@Args() params: ListParam, @Ctx() context: any): Promise<UserList> {
|
|
25
26
|
const { domain } = context.state
|
|
26
27
|
|
|
27
|
-
const convertedParams = convertListParams(params)
|
|
28
|
-
convertedParams.where = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
28
|
+
// const convertedParams = convertListParams(params)
|
|
29
|
+
// convertedParams.where = {
|
|
30
|
+
// ...convertedParams.where,
|
|
31
|
+
// userType: 'application'
|
|
32
|
+
// } as any
|
|
32
33
|
|
|
33
34
|
const alias: string = 'USER'
|
|
34
35
|
const qb: SelectQueryBuilder<User> = buildDomainUsersQueryBuilder(domain.id, alias)
|
|
@@ -7,8 +7,6 @@ import { AppliancePatch, NewAppliance } from './appliance-types'
|
|
|
7
7
|
|
|
8
8
|
const crypto = require('crypto')
|
|
9
9
|
|
|
10
|
-
const debug = require('debug')('things-factory:auth-base:appliance')
|
|
11
|
-
|
|
12
10
|
@Resolver(Appliance)
|
|
13
11
|
export class ApplianceMutation {
|
|
14
12
|
@Mutation(returns => Appliance, { description: 'To create new appliance' })
|
|
@@ -69,10 +67,7 @@ export class ApplianceMutation {
|
|
|
69
67
|
context.throw(401, 'appliance is not allowed for this domain')
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
debug('appiance user', appuser)
|
|
73
|
-
|
|
74
70
|
appuser.password = Appliance.generateAccessToken(domain, appuser, appliance)
|
|
75
|
-
debug('access token', appuser.password)
|
|
76
71
|
|
|
77
72
|
await getRepository(User).save(appuser)
|
|
78
73
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
|
2
2
|
import { getRepository } from 'typeorm'
|
|
3
|
+
|
|
3
4
|
import { User } from '../user/user'
|
|
4
5
|
import { Application } from './application'
|
|
5
|
-
import { ApplicationPatch, NewApplication
|
|
6
|
-
|
|
7
|
-
const debug = require('debug')('things-factory:auth-base:renew-application-access-token')
|
|
6
|
+
import { AccessToken, ApplicationPatch, NewApplication } from './application-types'
|
|
8
7
|
|
|
9
8
|
@Resolver(Application)
|
|
10
9
|
export class ApplicationMutation {
|
|
@@ -48,7 +47,6 @@ export class ApplicationMutation {
|
|
|
48
47
|
async renewApplicationAccessToken(@Arg('id') id: string, @Ctx() context: any, @Arg('scope') scope?: string) {
|
|
49
48
|
const { domain } = context.state
|
|
50
49
|
|
|
51
|
-
debug('renew-application-access-token', 'started')
|
|
52
50
|
var appuser: User = await getRepository(User).findOne({
|
|
53
51
|
id,
|
|
54
52
|
userType: 'application'
|
|
@@ -63,7 +61,6 @@ export class ApplicationMutation {
|
|
|
63
61
|
if (!application) {
|
|
64
62
|
throw new Error('application not found')
|
|
65
63
|
}
|
|
66
|
-
debug('application', application?.name)
|
|
67
64
|
|
|
68
65
|
var accessToken = Application.generateAccessToken(domain, appuser, application.appSecret, scope || '')
|
|
69
66
|
var refreshToken = Application.generateRefreshToken(domain, appuser, application.appSecret, scope || '')
|
|
@@ -58,7 +58,7 @@ export class GrantedRoleMutation {
|
|
|
58
58
|
|
|
59
59
|
let havingRefusedRoleCustomers: User[] = await getCustomerUsersByRoles(customerDomain, nonGrantedRoles, tx)
|
|
60
60
|
havingRefusedRoleCustomers = havingRefusedRoleCustomers.map((customerUser: User) => {
|
|
61
|
-
const customerDomains: Domain = customerUser.domains
|
|
61
|
+
const customerDomains: Domain[] = customerUser.domains
|
|
62
62
|
const customerDomainIds: string[] = customerDomains.map((domain: Domain) => domain.id)
|
|
63
63
|
if (customerDomainIds.indexOf(domain.id) >= 0) {
|
|
64
64
|
// Case for customer user is a member of current domain.
|
|
@@ -6,8 +6,6 @@ import { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils'
|
|
|
6
6
|
|
|
7
7
|
import { User } from '../user/user'
|
|
8
8
|
|
|
9
|
-
const debug = require('debug')('things-factory:auth-base:directive-privilege')
|
|
10
|
-
|
|
11
9
|
process['PRIVILEGES'] = {}
|
|
12
10
|
|
|
13
11
|
const DIRECTIVE = 'privilege'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
|
2
2
|
import { getRepository } from 'typeorm'
|
|
3
|
+
|
|
3
4
|
import { Role } from '../role/role'
|
|
4
5
|
import { Privilege } from './privilege'
|
|
5
6
|
import { NewPrivilege, PrivilegePatch } from './privilege-types'
|
|
@@ -34,9 +35,9 @@ export class PrivilegeMutation {
|
|
|
34
35
|
|
|
35
36
|
const roleIds = privilege.roles.map(role => role.id)
|
|
36
37
|
if (patch.roles && patch.roles.length) {
|
|
37
|
-
patch.roles.forEach((
|
|
38
|
-
if (!roleIds.includes(
|
|
39
|
-
roleIds.push(
|
|
38
|
+
patch.roles.forEach(({ id }) => {
|
|
39
|
+
if (!roleIds.includes(id)) {
|
|
40
|
+
roleIds.push(id)
|
|
40
41
|
}
|
|
41
42
|
})
|
|
42
43
|
}
|