@things-factory/oauth2-client 5.0.7 → 6.0.0-alpha.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/client/{bootstrap.js → bootstrap.ts} +0 -0
- package/{server/controllers → client}/index.ts +0 -0
- package/client/pages/oauth2-client/oauth2-client-importer.ts +97 -0
- package/client/pages/oauth2-client/oauth2-client-list-page.ts +337 -0
- package/client/pages/{oauth2-client-register.js → oauth2-client-register.ts} +79 -86
- package/client/pages/{oauth2-client.js → oauth2-client.ts} +157 -161
- package/client/pages/oauth2-clients.ts +192 -0
- package/client/{route.js → route.ts} +1 -1
- package/client/tsconfig.json +11 -0
- package/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +2 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/index.d.ts +0 -0
- package/dist-client/index.js +2 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/pages/oauth2-client/oauth2-client-importer.d.ts +22 -0
- package/dist-client/pages/oauth2-client/oauth2-client-importer.js +100 -0
- package/dist-client/pages/oauth2-client/oauth2-client-importer.js.map +1 -0
- package/dist-client/pages/oauth2-client/oauth2-client-list-page.d.ts +55 -0
- package/dist-client/pages/oauth2-client/oauth2-client-list-page.js +315 -0
- package/dist-client/pages/oauth2-client/oauth2-client-list-page.js.map +1 -0
- package/dist-client/pages/oauth2-client-register.d.ts +21 -0
- package/dist-client/pages/oauth2-client-register.js +190 -0
- package/dist-client/pages/oauth2-client-register.js.map +1 -0
- package/dist-client/pages/oauth2-client.d.ts +35 -0
- package/dist-client/pages/oauth2-client.js +586 -0
- package/dist-client/pages/oauth2-client.js.map +1 -0
- package/dist-client/pages/oauth2-clients.d.ts +1 -0
- package/dist-client/pages/oauth2-clients.js +194 -0
- package/dist-client/pages/oauth2-clients.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +14 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/index.d.ts +2 -0
- package/dist-server/index.js +2 -16
- package/dist-server/index.js.map +1 -1
- package/dist-server/routes.d.ts +1 -0
- package/dist-server/routes.js +10 -18
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/index.d.ts +5 -0
- package/dist-server/service/index.js +19 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/oauth2-client/index.d.ts +5 -0
- package/dist-server/service/oauth2-client/index.js +9 -0
- package/dist-server/service/oauth2-client/index.js.map +1 -0
- package/dist-server/service/oauth2-client/oauth2-client-mutation.d.ts +11 -0
- package/dist-server/service/oauth2-client/oauth2-client-mutation.js +165 -0
- package/dist-server/service/oauth2-client/oauth2-client-mutation.js.map +1 -0
- package/dist-server/service/oauth2-client/oauth2-client-query.d.ts +11 -0
- package/dist-server/service/oauth2-client/oauth2-client-query.js +79 -0
- package/dist-server/service/oauth2-client/oauth2-client-query.js.map +1 -0
- package/dist-server/service/oauth2-client/oauth2-client-type.d.ts +45 -0
- package/dist-server/service/oauth2-client/oauth2-client-type.js +177 -0
- package/dist-server/service/oauth2-client/oauth2-client-type.js.map +1 -0
- package/dist-server/service/oauth2-client/oauth2-client.d.ts +39 -0
- package/dist-server/service/oauth2-client/oauth2-client.js +220 -0
- package/dist-server/service/oauth2-client/oauth2-client.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +12 -10
- package/server/index.ts +2 -3
- package/server/routes.ts +9 -20
- package/server/service/index.ts +17 -0
- package/server/service/oauth2-client/index.ts +6 -0
- package/server/service/oauth2-client/oauth2-client-mutation.ts +188 -0
- package/server/service/oauth2-client/oauth2-client-query.ts +50 -0
- package/server/service/oauth2-client/oauth2-client-type.ts +126 -0
- package/server/service/oauth2-client/oauth2-client.ts +193 -0
- package/server/tsconfig.json +11 -0
- package/things-factory.config.js +5 -14
- package/client/index.js +0 -1
- package/client/pages/oauth2-clients.js +0 -197
- package/dist-server/controllers/index.js +0 -1
- package/dist-server/controllers/index.js.map +0 -1
- package/dist-server/entities/index.js +0 -9
- package/dist-server/entities/index.js.map +0 -1
- package/dist-server/entities/oauth2-client.js +0 -190
- package/dist-server/entities/oauth2-client.js.map +0 -1
- package/dist-server/graphql/index.js +0 -34
- package/dist-server/graphql/index.js.map +0 -1
- package/dist-server/graphql/resolvers/index.js +0 -18
- package/dist-server/graphql/resolvers/index.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/create-oauth2-client.js +0 -19
- package/dist-server/graphql/resolvers/oauth2-client/create-oauth2-client.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/delete-oauth2-client.js +0 -12
- package/dist-server/graphql/resolvers/oauth2-client/delete-oauth2-client.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/delete-oauth2-clients.js +0 -15
- package/dist-server/graphql/resolvers/oauth2-client/delete-oauth2-clients.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/get-oauth2-access-token.js +0 -49
- package/dist-server/graphql/resolvers/oauth2-client/get-oauth2-access-token.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/index.js +0 -15
- package/dist-server/graphql/resolvers/oauth2-client/index.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/oauth2-client-query.js +0 -46
- package/dist-server/graphql/resolvers/oauth2-client/oauth2-client-query.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/refresh-oauth2-access-token.js +0 -38
- package/dist-server/graphql/resolvers/oauth2-client/refresh-oauth2-access-token.js.map +0 -1
- package/dist-server/graphql/resolvers/oauth2-client/update-oauth2-client.js +0 -15
- package/dist-server/graphql/resolvers/oauth2-client/update-oauth2-client.js.map +0 -1
- package/dist-server/graphql/types/index.js +0 -18
- package/dist-server/graphql/types/index.js.map +0 -1
- package/dist-server/graphql/types/oauth2-client/index.js +0 -42
- package/dist-server/graphql/types/oauth2-client/index.js.map +0 -1
- package/dist-server/graphql/types/oauth2-client/new-oauth2-client.js +0 -30
- package/dist-server/graphql/types/oauth2-client/new-oauth2-client.js.map +0 -1
- package/dist-server/graphql/types/oauth2-client/oauth2-client-list.js +0 -14
- package/dist-server/graphql/types/oauth2-client/oauth2-client-list.js.map +0 -1
- package/dist-server/graphql/types/oauth2-client/oauth2-client-patch.js +0 -30
- package/dist-server/graphql/types/oauth2-client/oauth2-client-patch.js.map +0 -1
- package/dist-server/graphql/types/oauth2-client/oauth2-client.js +0 -38
- package/dist-server/graphql/types/oauth2-client/oauth2-client.js.map +0 -1
- package/server/entities/index.ts +0 -9
- package/server/entities/oauth2-client.ts +0 -156
- package/server/graphql/index.ts +0 -9
- package/server/graphql/resolvers/index.ts +0 -1
- package/server/graphql/resolvers/oauth2-client/create-oauth2-client.ts +0 -24
- package/server/graphql/resolvers/oauth2-client/delete-oauth2-client.ts +0 -10
- package/server/graphql/resolvers/oauth2-client/delete-oauth2-clients.ts +0 -13
- package/server/graphql/resolvers/oauth2-client/get-oauth2-access-token.ts +0 -64
- package/server/graphql/resolvers/oauth2-client/index.ts +0 -21
- package/server/graphql/resolvers/oauth2-client/oauth2-client-query.ts +0 -62
- package/server/graphql/resolvers/oauth2-client/refresh-oauth2-access-token.ts +0 -54
- package/server/graphql/resolvers/oauth2-client/update-oauth2-client.ts +0 -17
- package/server/graphql/types/index.ts +0 -1
- package/server/graphql/types/oauth2-client/index.ts +0 -23
- package/server/graphql/types/oauth2-client/new-oauth2-client.ts +0 -24
- package/server/graphql/types/oauth2-client/oauth2-client-list.ts +0 -8
- package/server/graphql/types/oauth2-client/oauth2-client-patch.ts +0 -24
- package/server/graphql/types/oauth2-client/oauth2-client.ts +0 -32
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* IMPORT ENTITIES AND RESOLVERS */
|
|
2
|
+
import { entities as Oauth2ClientEntities, resolvers as Oauth2ClientResolvers } from './oauth2-client'
|
|
3
|
+
|
|
4
|
+
/* EXPORT ENTITY TYPES */
|
|
5
|
+
export * from './oauth2-client/oauth2-client'
|
|
6
|
+
|
|
7
|
+
export const entities = [
|
|
8
|
+
/* ENTITIES */
|
|
9
|
+
...Oauth2ClientEntities
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
export const schema = {
|
|
13
|
+
resolverClasses: [
|
|
14
|
+
/* RESOLVER CLASSES */
|
|
15
|
+
...Oauth2ClientResolvers
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Oauth2Client } from './oauth2-client'
|
|
2
|
+
import { Oauth2ClientQuery } from './oauth2-client-query'
|
|
3
|
+
import { Oauth2ClientMutation } from './oauth2-client-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [Oauth2Client]
|
|
6
|
+
export const resolvers = [Oauth2ClientQuery, Oauth2ClientMutation]
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import ClientOAuth2 from 'client-oauth2'
|
|
2
|
+
import crypto from 'crypto'
|
|
3
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
4
|
+
import { In } from 'typeorm'
|
|
5
|
+
|
|
6
|
+
import { config } from '@things-factory/env'
|
|
7
|
+
|
|
8
|
+
import { Oauth2Client } from './oauth2-client'
|
|
9
|
+
import { NewOauth2Client, Oauth2ClientPatch } from './oauth2-client-type'
|
|
10
|
+
|
|
11
|
+
const protocol: string = config.get('protocol')
|
|
12
|
+
|
|
13
|
+
@Resolver(Oauth2Client)
|
|
14
|
+
export class Oauth2ClientMutation {
|
|
15
|
+
@Directive('@transaction')
|
|
16
|
+
@Mutation(returns => Oauth2Client, { description: 'To create new Oauth2Client' })
|
|
17
|
+
async createOauth2Client(
|
|
18
|
+
@Arg('oauth2Client') oauth2Client: NewOauth2Client,
|
|
19
|
+
@Ctx() context: ResolverContext
|
|
20
|
+
): Promise<Oauth2Client> {
|
|
21
|
+
const { origin } = context
|
|
22
|
+
const { domain, user, tx } = context.state
|
|
23
|
+
|
|
24
|
+
let url: URL = new URL(origin)
|
|
25
|
+
url.protocol = protocol || url.protocol
|
|
26
|
+
url.pathname = '/oauth2-client/callback'
|
|
27
|
+
|
|
28
|
+
return await tx.getRepository(Oauth2Client).save({
|
|
29
|
+
...oauth2Client,
|
|
30
|
+
callbackUrl: oauth2Client.callbackUrl || url.href,
|
|
31
|
+
domain,
|
|
32
|
+
creator: user,
|
|
33
|
+
updater: user
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Directive('@transaction')
|
|
38
|
+
@Mutation(returns => Oauth2Client, { description: 'To modify Oauth2Client information' })
|
|
39
|
+
async updateOauth2Client(
|
|
40
|
+
@Arg('id') id: string,
|
|
41
|
+
@Arg('patch') patch: Oauth2ClientPatch,
|
|
42
|
+
@Ctx() context: ResolverContext
|
|
43
|
+
): Promise<Oauth2Client> {
|
|
44
|
+
const { domain, user, tx } = context.state
|
|
45
|
+
|
|
46
|
+
const repository = tx.getRepository(Oauth2Client)
|
|
47
|
+
const oauth2Client = await repository.findOne({
|
|
48
|
+
where: { domain: { id: domain.id }, id }
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return await repository.save({
|
|
52
|
+
...oauth2Client,
|
|
53
|
+
...patch,
|
|
54
|
+
updater: user
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Directive('@transaction')
|
|
59
|
+
@Mutation(returns => Boolean, { description: 'To delete Oauth2Client' })
|
|
60
|
+
async deleteOauth2Client(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
61
|
+
const { domain, tx } = context.state
|
|
62
|
+
|
|
63
|
+
await tx.getRepository(Oauth2Client).delete({ domain: { id: domain.id }, id })
|
|
64
|
+
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Directive('@transaction')
|
|
69
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple Oauth2Clients' })
|
|
70
|
+
async deleteOauth2Clients(
|
|
71
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
72
|
+
@Ctx() context: ResolverContext
|
|
73
|
+
): Promise<boolean> {
|
|
74
|
+
const { domain, tx } = context.state
|
|
75
|
+
|
|
76
|
+
await tx.getRepository(Oauth2Client).delete({
|
|
77
|
+
domain: { id: domain.id },
|
|
78
|
+
id: In(ids)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return true
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Directive('@transaction')
|
|
85
|
+
@Mutation(returns => Boolean, { description: 'To import multiple Oauth2Clients' })
|
|
86
|
+
async importOauth2Clients(
|
|
87
|
+
@Arg('oauth2Clients', type => [Oauth2ClientPatch]) oauth2Clients: Oauth2ClientPatch[],
|
|
88
|
+
@Ctx() context: ResolverContext
|
|
89
|
+
): Promise<boolean> {
|
|
90
|
+
const { domain, tx } = context.state
|
|
91
|
+
|
|
92
|
+
await Promise.all(
|
|
93
|
+
oauth2Clients.map(async (oauth2Client: Oauth2ClientPatch) => {
|
|
94
|
+
const createdOauth2Client: Oauth2Client = await tx.getRepository(Oauth2Client).save({ domain, ...oauth2Client })
|
|
95
|
+
})
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Directive('@transaction')
|
|
102
|
+
@Mutation(returns => String, { description: 'To get oauth2 auth URL' })
|
|
103
|
+
async getOauth2AuthUrl(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<string> {
|
|
104
|
+
const { tx } = context.state
|
|
105
|
+
const repository = tx.getRepository(Oauth2Client)
|
|
106
|
+
const oauth2Client = await repository.findOneBy({ id })
|
|
107
|
+
|
|
108
|
+
const {
|
|
109
|
+
grantType,
|
|
110
|
+
clientId,
|
|
111
|
+
clientSecret,
|
|
112
|
+
callbackUrl,
|
|
113
|
+
accessTokenUrl: accessTokenUri,
|
|
114
|
+
authUrl: authorizationUri,
|
|
115
|
+
scopes
|
|
116
|
+
} = oauth2Client
|
|
117
|
+
|
|
118
|
+
if (grantType !== 'code') {
|
|
119
|
+
throw new Error(`unsupported grant type: ${grantType}`)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const state = crypto.randomBytes(16).toString('hex')
|
|
123
|
+
await repository.save({
|
|
124
|
+
...oauth2Client,
|
|
125
|
+
state
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
var auth = new ClientOAuth2({
|
|
129
|
+
clientId,
|
|
130
|
+
clientSecret,
|
|
131
|
+
accessTokenUri,
|
|
132
|
+
authorizationUri,
|
|
133
|
+
redirectUri: callbackUrl || `${context.origin}/oauth2-client/callback`,
|
|
134
|
+
scopes: scopes?.split(' ') || [],
|
|
135
|
+
state
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
return await (auth[grantType] as any).getUri()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@Directive('@transaction')
|
|
142
|
+
@Mutation(returns => Oauth2Client, { description: 'To refresh oauth2 access token' })
|
|
143
|
+
async refreshOauth2AccessToken(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Oauth2Client> {
|
|
144
|
+
const { tx } = context.state
|
|
145
|
+
const repository = tx.getRepository(Oauth2Client)
|
|
146
|
+
const oauth2Client = await repository.findOneBy({ id })
|
|
147
|
+
|
|
148
|
+
const {
|
|
149
|
+
clientId,
|
|
150
|
+
clientSecret,
|
|
151
|
+
accessTokenUrl: accessTokenUri,
|
|
152
|
+
authUrl: authorizationUri,
|
|
153
|
+
scopes,
|
|
154
|
+
tokenType,
|
|
155
|
+
accessToken,
|
|
156
|
+
refreshToken
|
|
157
|
+
} = oauth2Client
|
|
158
|
+
|
|
159
|
+
if (!refreshToken) {
|
|
160
|
+
throw new Error('refreshToken not found')
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
var auth = new ClientOAuth2({
|
|
164
|
+
clientId,
|
|
165
|
+
clientSecret,
|
|
166
|
+
accessTokenUri,
|
|
167
|
+
authorizationUri,
|
|
168
|
+
scopes: scopes?.split(' ')
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
var token = await auth.createToken(accessToken, refreshToken, tokenType, {}).refresh()
|
|
173
|
+
} catch (err) {
|
|
174
|
+
throw err
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const { accessToken: newAccessToken, refreshToken: newRefreshToken, tokenType: newTokenType, data } = token
|
|
178
|
+
const expires = data?.expires_in ? token.expiresIn(data?.expires_in as any) : null
|
|
179
|
+
|
|
180
|
+
return await repository.save({
|
|
181
|
+
...oauth2Client,
|
|
182
|
+
accessToken: newAccessToken,
|
|
183
|
+
refreshToken: newRefreshToken,
|
|
184
|
+
tokenType: newTokenType,
|
|
185
|
+
expires
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { Oauth2Client } from './oauth2-client'
|
|
7
|
+
import { Oauth2ClientList } from './oauth2-client-type'
|
|
8
|
+
|
|
9
|
+
@Resolver(Oauth2Client)
|
|
10
|
+
export class Oauth2ClientQuery {
|
|
11
|
+
@Query(returns => Oauth2Client!, { nullable: true, description: 'To fetch a Oauth2Client' })
|
|
12
|
+
async oauth2Client(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Oauth2Client> {
|
|
13
|
+
const { domain } = context.state
|
|
14
|
+
|
|
15
|
+
return await getRepository(Oauth2Client).findOne({
|
|
16
|
+
where: { domain: { id: domain.id }, id }
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Query(returns => Oauth2ClientList, { description: 'To fetch multiple Oauth2Clients' })
|
|
21
|
+
async oauth2Clients(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<Oauth2ClientList> {
|
|
22
|
+
const { domain } = context.state
|
|
23
|
+
|
|
24
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
25
|
+
domain,
|
|
26
|
+
params,
|
|
27
|
+
repository: await getRepository(Oauth2Client),
|
|
28
|
+
searchables: ['name', 'description']
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
32
|
+
|
|
33
|
+
return { items, total }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@FieldResolver(type => Domain)
|
|
37
|
+
async domain(@Root() oauth2Client: Oauth2Client): Promise<Domain> {
|
|
38
|
+
return await getRepository(Domain).findOneBy({ id: oauth2Client.domainId })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@FieldResolver(type => User)
|
|
42
|
+
async updater(@Root() oauth2Client: Oauth2Client): Promise<User> {
|
|
43
|
+
return await getRepository(User).findOneBy({ id: oauth2Client.updaterId })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@FieldResolver(type => User)
|
|
47
|
+
async creator(@Root() oauth2Client: Oauth2Client): Promise<User> {
|
|
48
|
+
return await getRepository(User).findOneBy({ id: oauth2Client.creatorId })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Field, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Oauth2Client } from './oauth2-client'
|
|
4
|
+
|
|
5
|
+
@InputType()
|
|
6
|
+
export class NewOauth2Client {
|
|
7
|
+
@Field()
|
|
8
|
+
name: string
|
|
9
|
+
|
|
10
|
+
@Field({ nullable: true })
|
|
11
|
+
description?: string
|
|
12
|
+
|
|
13
|
+
@Field({ nullable: true })
|
|
14
|
+
icon?: string
|
|
15
|
+
|
|
16
|
+
@Field({ nullable: true })
|
|
17
|
+
grantType?: string
|
|
18
|
+
|
|
19
|
+
@Field({ nullable: true })
|
|
20
|
+
clientId?: string
|
|
21
|
+
|
|
22
|
+
@Field({ nullable: true })
|
|
23
|
+
clientSecret?: string
|
|
24
|
+
|
|
25
|
+
@Field({ nullable: true })
|
|
26
|
+
callbackUrl?: string
|
|
27
|
+
|
|
28
|
+
@Field({ nullable: true })
|
|
29
|
+
authUrl?: string
|
|
30
|
+
|
|
31
|
+
@Field({ nullable: true })
|
|
32
|
+
accessTokenUrl?: string
|
|
33
|
+
|
|
34
|
+
@Field({ nullable: true })
|
|
35
|
+
webhook?: string
|
|
36
|
+
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
username?: string
|
|
39
|
+
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
password?: string
|
|
42
|
+
|
|
43
|
+
@Field({ nullable: true })
|
|
44
|
+
codeChallengeMethod?: string
|
|
45
|
+
|
|
46
|
+
@Field({ nullable: true })
|
|
47
|
+
codeVerifier?: string
|
|
48
|
+
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
scopes?: string
|
|
51
|
+
|
|
52
|
+
@Field({ nullable: true })
|
|
53
|
+
accessToken?: string
|
|
54
|
+
|
|
55
|
+
@Field({ nullable: true })
|
|
56
|
+
refreshToken?: string
|
|
57
|
+
|
|
58
|
+
@Field({ nullable: true })
|
|
59
|
+
jwtToken?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@InputType()
|
|
63
|
+
export class Oauth2ClientPatch {
|
|
64
|
+
@Field({ nullable: true })
|
|
65
|
+
name?: string
|
|
66
|
+
|
|
67
|
+
@Field({ nullable: true })
|
|
68
|
+
description?: string
|
|
69
|
+
|
|
70
|
+
@Field({ nullable: true })
|
|
71
|
+
icon?: string
|
|
72
|
+
|
|
73
|
+
@Field({ nullable: true })
|
|
74
|
+
grantType?: string
|
|
75
|
+
|
|
76
|
+
@Field({ nullable: true })
|
|
77
|
+
clientId?: string
|
|
78
|
+
|
|
79
|
+
@Field({ nullable: true })
|
|
80
|
+
clientSecret?: string
|
|
81
|
+
|
|
82
|
+
@Field({ nullable: true })
|
|
83
|
+
callbackUrl?: string
|
|
84
|
+
|
|
85
|
+
@Field({ nullable: true })
|
|
86
|
+
authUrl?: string
|
|
87
|
+
|
|
88
|
+
@Field({ nullable: true })
|
|
89
|
+
accessTokenUrl?: string
|
|
90
|
+
|
|
91
|
+
@Field({ nullable: true })
|
|
92
|
+
webhook?: string
|
|
93
|
+
|
|
94
|
+
@Field({ nullable: true })
|
|
95
|
+
username?: string
|
|
96
|
+
|
|
97
|
+
@Field({ nullable: true })
|
|
98
|
+
password?: string
|
|
99
|
+
|
|
100
|
+
@Field({ nullable: true })
|
|
101
|
+
codeChallengeMethod?: string
|
|
102
|
+
|
|
103
|
+
@Field({ nullable: true })
|
|
104
|
+
codeVerifier?: string
|
|
105
|
+
|
|
106
|
+
@Field({ nullable: true })
|
|
107
|
+
scopes?: string
|
|
108
|
+
|
|
109
|
+
@Field({ nullable: true })
|
|
110
|
+
accessToken?: string
|
|
111
|
+
|
|
112
|
+
@Field({ nullable: true })
|
|
113
|
+
refreshToken?: string
|
|
114
|
+
|
|
115
|
+
@Field({ nullable: true })
|
|
116
|
+
jwtToken?: string
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@ObjectType()
|
|
120
|
+
export class Oauth2ClientList {
|
|
121
|
+
@Field(type => [Oauth2Client])
|
|
122
|
+
items: Oauth2Client[]
|
|
123
|
+
|
|
124
|
+
@Field(type => Int)
|
|
125
|
+
total: number
|
|
126
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
Index,
|
|
7
|
+
ManyToOne,
|
|
8
|
+
PrimaryGeneratedColumn,
|
|
9
|
+
RelationId,
|
|
10
|
+
UpdateDateColumn
|
|
11
|
+
} from 'typeorm'
|
|
12
|
+
|
|
13
|
+
import { User } from '@things-factory/auth-base'
|
|
14
|
+
import { Domain } from '@things-factory/shell'
|
|
15
|
+
|
|
16
|
+
@Entity()
|
|
17
|
+
@Index('ix_oauth2_client_0', (oauth2Client: Oauth2Client) => [oauth2Client.domain, oauth2Client.name], { unique: true })
|
|
18
|
+
@ObjectType({ description: 'Entity for Oauth2Client' })
|
|
19
|
+
export class Oauth2Client {
|
|
20
|
+
@PrimaryGeneratedColumn('uuid')
|
|
21
|
+
@Field(type => ID)
|
|
22
|
+
readonly id: string
|
|
23
|
+
|
|
24
|
+
@ManyToOne(type => Domain)
|
|
25
|
+
@Field({ nullable: true })
|
|
26
|
+
domain?: Domain
|
|
27
|
+
|
|
28
|
+
@RelationId((oauth2Client: Oauth2Client) => oauth2Client.domain)
|
|
29
|
+
domainId?: string
|
|
30
|
+
|
|
31
|
+
@Column()
|
|
32
|
+
@Field()
|
|
33
|
+
name: string
|
|
34
|
+
|
|
35
|
+
@Column({
|
|
36
|
+
nullable: true
|
|
37
|
+
})
|
|
38
|
+
@Field({ nullable: true })
|
|
39
|
+
description?: string
|
|
40
|
+
|
|
41
|
+
@Column({
|
|
42
|
+
nullable: true
|
|
43
|
+
})
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
icon?: string
|
|
46
|
+
|
|
47
|
+
@Column({
|
|
48
|
+
nullable: true
|
|
49
|
+
})
|
|
50
|
+
@Field({ nullable: true })
|
|
51
|
+
grantType?: string
|
|
52
|
+
|
|
53
|
+
@Column({
|
|
54
|
+
nullable: true
|
|
55
|
+
})
|
|
56
|
+
@Field({ nullable: true })
|
|
57
|
+
clientId?: string
|
|
58
|
+
|
|
59
|
+
@Column({
|
|
60
|
+
nullable: true
|
|
61
|
+
})
|
|
62
|
+
@Field({ nullable: true })
|
|
63
|
+
clientSecret?: string
|
|
64
|
+
|
|
65
|
+
@Column({
|
|
66
|
+
nullable: true
|
|
67
|
+
})
|
|
68
|
+
@Field({ nullable: true })
|
|
69
|
+
accessTokenUrl?: string
|
|
70
|
+
|
|
71
|
+
@Column({
|
|
72
|
+
nullable: true
|
|
73
|
+
})
|
|
74
|
+
@Field({ nullable: true })
|
|
75
|
+
authUrl?: string
|
|
76
|
+
|
|
77
|
+
@Column({
|
|
78
|
+
nullable: true
|
|
79
|
+
})
|
|
80
|
+
@Field({ nullable: true })
|
|
81
|
+
callbackUrl?: string
|
|
82
|
+
|
|
83
|
+
@Column({
|
|
84
|
+
nullable: true
|
|
85
|
+
})
|
|
86
|
+
@Field({ nullable: true })
|
|
87
|
+
webhook?: string
|
|
88
|
+
|
|
89
|
+
@Column({
|
|
90
|
+
nullable: true
|
|
91
|
+
})
|
|
92
|
+
@Field({ nullable: true })
|
|
93
|
+
username?: string
|
|
94
|
+
|
|
95
|
+
@Column({
|
|
96
|
+
nullable: true
|
|
97
|
+
})
|
|
98
|
+
@Field({ nullable: true })
|
|
99
|
+
password?: string
|
|
100
|
+
|
|
101
|
+
@Column({
|
|
102
|
+
nullable: true
|
|
103
|
+
})
|
|
104
|
+
@Field({ nullable: true })
|
|
105
|
+
codeChallengeMethod?: string
|
|
106
|
+
|
|
107
|
+
@Column({
|
|
108
|
+
nullable: true
|
|
109
|
+
})
|
|
110
|
+
@Field({ nullable: true })
|
|
111
|
+
codeVerifier?: string
|
|
112
|
+
|
|
113
|
+
@Column({
|
|
114
|
+
nullable: true
|
|
115
|
+
})
|
|
116
|
+
@Field({ nullable: true })
|
|
117
|
+
scopes?: string
|
|
118
|
+
|
|
119
|
+
@Column({
|
|
120
|
+
nullable: true
|
|
121
|
+
})
|
|
122
|
+
@Field({ nullable: true })
|
|
123
|
+
accessToken?: string
|
|
124
|
+
|
|
125
|
+
@Column({
|
|
126
|
+
nullable: true
|
|
127
|
+
})
|
|
128
|
+
@Field({ nullable: true })
|
|
129
|
+
refreshToken?: string
|
|
130
|
+
|
|
131
|
+
@Column()
|
|
132
|
+
@Field({ nullable: true })
|
|
133
|
+
expires?: Date
|
|
134
|
+
|
|
135
|
+
@Column({
|
|
136
|
+
nullable: true
|
|
137
|
+
})
|
|
138
|
+
@Field({ nullable: true })
|
|
139
|
+
state?: string
|
|
140
|
+
|
|
141
|
+
@Column({
|
|
142
|
+
nullable: true
|
|
143
|
+
})
|
|
144
|
+
@Field({ nullable: true })
|
|
145
|
+
jwtToken?: string
|
|
146
|
+
|
|
147
|
+
@Column({
|
|
148
|
+
nullable: true
|
|
149
|
+
})
|
|
150
|
+
@Field({ nullable: true })
|
|
151
|
+
tokenType?: string
|
|
152
|
+
|
|
153
|
+
@CreateDateColumn()
|
|
154
|
+
@Field({ nullable: true })
|
|
155
|
+
createdAt?: Date
|
|
156
|
+
|
|
157
|
+
@UpdateDateColumn()
|
|
158
|
+
@Field({ nullable: true })
|
|
159
|
+
updatedAt?: Date
|
|
160
|
+
|
|
161
|
+
@ManyToOne(type => User, {
|
|
162
|
+
nullable: true
|
|
163
|
+
})
|
|
164
|
+
@Field({ nullable: true })
|
|
165
|
+
creator?: User
|
|
166
|
+
|
|
167
|
+
@RelationId((oauth2Client: Oauth2Client) => oauth2Client.creator)
|
|
168
|
+
creatorId?: string
|
|
169
|
+
|
|
170
|
+
@ManyToOne(type => User, {
|
|
171
|
+
nullable: true
|
|
172
|
+
})
|
|
173
|
+
@Field({ nullable: true })
|
|
174
|
+
updater?: User
|
|
175
|
+
|
|
176
|
+
@RelationId((oauth2Client: Oauth2Client) => oauth2Client.creator)
|
|
177
|
+
updaterId?: string
|
|
178
|
+
|
|
179
|
+
getAuthHeaders() {
|
|
180
|
+
if (this.tokenType == 'bearer') {
|
|
181
|
+
return {
|
|
182
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
183
|
+
}
|
|
184
|
+
} else if (this.tokenType == 'basic' || !this.tokenType) {
|
|
185
|
+
const encoded = Buffer.from(`${this.username}:${this.password}`).toString('base64')
|
|
186
|
+
return {
|
|
187
|
+
Authorization: `Basic ${encoded}`
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {}
|
|
192
|
+
}
|
|
193
|
+
}
|
package/things-factory.config.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import bootstrap from './dist-client/bootstrap'
|
|
2
|
+
import route from './dist-client/route'
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
route,
|
|
6
6
|
routes: [
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
tagname: 'oauth2-clients',
|
|
13
|
-
page: 'oauth2-clients'
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
tagname: 'oauth2-client',
|
|
17
|
-
page: 'oauth2-client'
|
|
18
|
-
}
|
|
7
|
+
{ tagname: 'oauth2-client-register', page: 'oauth2-client-register' },
|
|
8
|
+
{ tagname: 'oauth2-clients', page: 'oauth2-clients' },
|
|
9
|
+
{ tagname: 'oauth2-client', page: 'oauth2-client' }
|
|
19
10
|
],
|
|
20
11
|
bootstrap
|
|
21
12
|
}
|
package/client/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './actions/oauth2-client'
|