@things-factory/oauth2-client 5.0.11 → 6.0.0-alpha.3
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 +1 -2
- package/dist-server/index.js.map +1 -1
- package/dist-server/routes.d.ts +1 -0
- package/dist-server/routes.js +7 -9
- 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/{entities → service/oauth2-client}/oauth2-client.js +47 -9
- package/dist-server/service/oauth2-client/oauth2-client.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -10
- package/server/index.ts +2 -3
- package/server/routes.ts +8 -13
- 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.map +0 -1
- package/dist-server/graphql/index.js +0 -12
- package/dist-server/graphql/index.js.map +0 -1
- package/dist-server/graphql/resolvers/index.js +0 -5
- 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 -45
- 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 -44
- 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 -34
- 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 -5
- package/dist-server/graphql/types/index.js.map +0 -1
- package/dist-server/graphql/types/oauth2-client/index.js +0 -26
- package/dist-server/graphql/types/oauth2-client/index.js.map +0 -1
- package/dist-server/graphql/types/oauth2-client/new-oauth2-client.js +0 -28
- 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 -12
- 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 -28
- 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 -36
- 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 -60
- 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 -51
- 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
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Oauth2ClientList = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
6
|
-
exports.Oauth2ClientList = (0, graphql_tag_1.default) `
|
|
7
|
-
type Oauth2ClientList {
|
|
8
|
-
items: [Oauth2Client]
|
|
9
|
-
total: Int
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
12
|
-
//# sourceMappingURL=oauth2-client-list.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth2-client-list.js","sourceRoot":"","sources":["../../../../server/graphql/types/oauth2-client/oauth2-client-list.ts"],"names":[],"mappings":";;;;AAAA,sEAA6B;AAEhB,QAAA,gBAAgB,GAAG,IAAA,qBAAG,EAAA;;;;;CAKlC,CAAA","sourcesContent":["import gql from 'graphql-tag'\n\nexport const Oauth2ClientList = gql`\n type Oauth2ClientList {\n items: [Oauth2Client]\n total: Int\n }\n`\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Oauth2ClientPatch = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
6
|
-
exports.Oauth2ClientPatch = (0, graphql_tag_1.default) `
|
|
7
|
-
input Oauth2ClientPatch {
|
|
8
|
-
name: String
|
|
9
|
-
description: String
|
|
10
|
-
icon: String
|
|
11
|
-
grantType: String
|
|
12
|
-
clientId: String
|
|
13
|
-
clientSecret: String
|
|
14
|
-
callbackUrl: String
|
|
15
|
-
authUrl: String
|
|
16
|
-
accessTokenUrl: String
|
|
17
|
-
webhook: String
|
|
18
|
-
username: String
|
|
19
|
-
password: String
|
|
20
|
-
codeChallengeMethod: String
|
|
21
|
-
codeVerifier: String
|
|
22
|
-
scopes: String
|
|
23
|
-
accessToken: String
|
|
24
|
-
refreshToken: String
|
|
25
|
-
jwtToken: String
|
|
26
|
-
}
|
|
27
|
-
`;
|
|
28
|
-
//# sourceMappingURL=oauth2-client-patch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth2-client-patch.js","sourceRoot":"","sources":["../../../../server/graphql/types/oauth2-client/oauth2-client-patch.ts"],"names":[],"mappings":";;;;AAAA,sEAA6B;AAEhB,QAAA,iBAAiB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;CAqBnC,CAAA","sourcesContent":["import gql from 'graphql-tag'\n\nexport const Oauth2ClientPatch = gql`\n input Oauth2ClientPatch {\n name: String\n description: String\n icon: String\n grantType: String\n clientId: String\n clientSecret: String\n callbackUrl: String\n authUrl: String\n accessTokenUrl: String\n webhook: String\n username: String\n password: String\n codeChallengeMethod: String\n codeVerifier: String\n scopes: String\n accessToken: String\n refreshToken: String\n jwtToken: String\n }\n`\n"]}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Oauth2Client = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
6
|
-
exports.Oauth2Client = (0, graphql_tag_1.default) `
|
|
7
|
-
type Oauth2Client {
|
|
8
|
-
id: String
|
|
9
|
-
domain: Domain
|
|
10
|
-
name: String
|
|
11
|
-
description: String
|
|
12
|
-
icon: String
|
|
13
|
-
grantType: String
|
|
14
|
-
clientId: String
|
|
15
|
-
clientSecret: String
|
|
16
|
-
callbackUrl: String
|
|
17
|
-
authUrl: String
|
|
18
|
-
accessTokenUrl: String
|
|
19
|
-
webhook: String
|
|
20
|
-
username: String
|
|
21
|
-
password: String
|
|
22
|
-
codeChallengeMethod: String
|
|
23
|
-
codeVerifier: String
|
|
24
|
-
scopes: String
|
|
25
|
-
accessToken: String
|
|
26
|
-
refreshToken: String
|
|
27
|
-
expires: String
|
|
28
|
-
jwtToken: String
|
|
29
|
-
tokenType: String
|
|
30
|
-
updater: User
|
|
31
|
-
creator: User
|
|
32
|
-
updatedAt: String
|
|
33
|
-
createdAt: String
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
//# sourceMappingURL=oauth2-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth2-client.js","sourceRoot":"","sources":["../../../../server/graphql/types/oauth2-client/oauth2-client.ts"],"names":[],"mappings":";;;;AAAA,sEAA6B;AAEhB,QAAA,YAAY,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B9B,CAAA","sourcesContent":["import gql from 'graphql-tag'\n\nexport const Oauth2Client = gql`\n type Oauth2Client {\n id: String\n domain: Domain\n name: String\n description: String\n icon: String\n grantType: String\n clientId: String\n clientSecret: String\n callbackUrl: String\n authUrl: String\n accessTokenUrl: String\n webhook: String\n username: String\n password: String\n codeChallengeMethod: String\n codeVerifier: String\n scopes: String\n accessToken: String\n refreshToken: String\n expires: String\n jwtToken: String\n tokenType: String\n updater: User\n creator: User\n updatedAt: String\n createdAt: String\n }\n`\n"]}
|
package/server/entities/index.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CreateDateColumn,
|
|
3
|
-
UpdateDateColumn,
|
|
4
|
-
Entity,
|
|
5
|
-
Index,
|
|
6
|
-
Column,
|
|
7
|
-
OneToMany,
|
|
8
|
-
ManyToOne,
|
|
9
|
-
PrimaryGeneratedColumn
|
|
10
|
-
} from 'typeorm'
|
|
11
|
-
import { Domain } from '@things-factory/shell'
|
|
12
|
-
import { User } from '@things-factory/auth-base'
|
|
13
|
-
|
|
14
|
-
@Entity()
|
|
15
|
-
@Index('ix_oauth2_client_0', (oauth2Client: Oauth2Client) => [oauth2Client.domain, oauth2Client.name], { unique: true })
|
|
16
|
-
export class Oauth2Client {
|
|
17
|
-
@PrimaryGeneratedColumn('uuid')
|
|
18
|
-
id: string
|
|
19
|
-
|
|
20
|
-
@ManyToOne(type => Domain)
|
|
21
|
-
domain: Domain
|
|
22
|
-
|
|
23
|
-
@Column()
|
|
24
|
-
name: string
|
|
25
|
-
|
|
26
|
-
@Column({
|
|
27
|
-
nullable: true
|
|
28
|
-
})
|
|
29
|
-
description: string
|
|
30
|
-
|
|
31
|
-
@Column({
|
|
32
|
-
nullable: true
|
|
33
|
-
})
|
|
34
|
-
icon: string
|
|
35
|
-
|
|
36
|
-
@Column({
|
|
37
|
-
nullable: true
|
|
38
|
-
})
|
|
39
|
-
grantType: string
|
|
40
|
-
|
|
41
|
-
@Column({
|
|
42
|
-
nullable: true
|
|
43
|
-
})
|
|
44
|
-
clientId: string
|
|
45
|
-
|
|
46
|
-
@Column({
|
|
47
|
-
nullable: true
|
|
48
|
-
})
|
|
49
|
-
clientSecret: string
|
|
50
|
-
|
|
51
|
-
@Column({
|
|
52
|
-
nullable: true
|
|
53
|
-
})
|
|
54
|
-
accessTokenUrl: string
|
|
55
|
-
|
|
56
|
-
@Column({
|
|
57
|
-
nullable: true
|
|
58
|
-
})
|
|
59
|
-
authUrl: string
|
|
60
|
-
|
|
61
|
-
@Column({
|
|
62
|
-
nullable: true
|
|
63
|
-
})
|
|
64
|
-
callbackUrl: string
|
|
65
|
-
|
|
66
|
-
@Column({
|
|
67
|
-
nullable: true
|
|
68
|
-
})
|
|
69
|
-
webhook: string
|
|
70
|
-
|
|
71
|
-
@Column({
|
|
72
|
-
nullable: true
|
|
73
|
-
})
|
|
74
|
-
username: string
|
|
75
|
-
|
|
76
|
-
@Column({
|
|
77
|
-
nullable: true
|
|
78
|
-
})
|
|
79
|
-
password: string
|
|
80
|
-
|
|
81
|
-
@Column({
|
|
82
|
-
nullable: true
|
|
83
|
-
})
|
|
84
|
-
codeChallengeMethod: string
|
|
85
|
-
|
|
86
|
-
@Column({
|
|
87
|
-
nullable: true
|
|
88
|
-
})
|
|
89
|
-
codeVerifier: string
|
|
90
|
-
|
|
91
|
-
@Column({
|
|
92
|
-
nullable: true
|
|
93
|
-
})
|
|
94
|
-
scopes: string
|
|
95
|
-
|
|
96
|
-
@Column({
|
|
97
|
-
nullable: true
|
|
98
|
-
})
|
|
99
|
-
accessToken: string
|
|
100
|
-
|
|
101
|
-
@Column({
|
|
102
|
-
nullable: true
|
|
103
|
-
})
|
|
104
|
-
refreshToken: string
|
|
105
|
-
|
|
106
|
-
@Column({
|
|
107
|
-
nullable: true
|
|
108
|
-
})
|
|
109
|
-
expires: Date
|
|
110
|
-
|
|
111
|
-
@Column({
|
|
112
|
-
nullable: true
|
|
113
|
-
})
|
|
114
|
-
state: string
|
|
115
|
-
|
|
116
|
-
@Column({
|
|
117
|
-
nullable: true
|
|
118
|
-
})
|
|
119
|
-
jwtToken: string
|
|
120
|
-
|
|
121
|
-
@Column({
|
|
122
|
-
nullable: true
|
|
123
|
-
})
|
|
124
|
-
tokenType: string
|
|
125
|
-
|
|
126
|
-
@CreateDateColumn()
|
|
127
|
-
createdAt: Date
|
|
128
|
-
|
|
129
|
-
@UpdateDateColumn()
|
|
130
|
-
updatedAt: Date
|
|
131
|
-
|
|
132
|
-
@ManyToOne(type => User, {
|
|
133
|
-
nullable: true
|
|
134
|
-
})
|
|
135
|
-
creator: User
|
|
136
|
-
|
|
137
|
-
@ManyToOne(type => User, {
|
|
138
|
-
nullable: true
|
|
139
|
-
})
|
|
140
|
-
updater: User
|
|
141
|
-
|
|
142
|
-
getAuthHeaders() {
|
|
143
|
-
if (this.tokenType == 'bearer') {
|
|
144
|
-
return {
|
|
145
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
146
|
-
}
|
|
147
|
-
} else if (this.tokenType == 'basic' || !this.tokenType) {
|
|
148
|
-
const encoded = Buffer.from(`${this.username}:${this.password}`).toString('base64')
|
|
149
|
-
return {
|
|
150
|
-
Authorization: `Basic ${encoded}`
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return {}
|
|
155
|
-
}
|
|
156
|
-
}
|
package/server/graphql/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './oauth2-client'
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { config } from '@things-factory/env'
|
|
2
|
-
import { getRepository } from 'typeorm'
|
|
3
|
-
import { URL } from 'url'
|
|
4
|
-
import { Oauth2Client } from '../../../entities'
|
|
5
|
-
const protocol: string = config.get('protocol')
|
|
6
|
-
|
|
7
|
-
export const createOauth2Client = {
|
|
8
|
-
async createOauth2Client(_: any, { oauth2Client }, context: any) {
|
|
9
|
-
const { origin } = context
|
|
10
|
-
let url: URL = new URL(origin)
|
|
11
|
-
url.protocol = protocol || url.protocol
|
|
12
|
-
url.pathname = '/oauth2-client/callback'
|
|
13
|
-
|
|
14
|
-
const { domain, user } = context.state
|
|
15
|
-
|
|
16
|
-
return await getRepository(Oauth2Client).save({
|
|
17
|
-
...oauth2Client,
|
|
18
|
-
callbackUrl: oauth2Client.callbackUrl || url.href,
|
|
19
|
-
domain: domain,
|
|
20
|
-
creator: user,
|
|
21
|
-
updater: user
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getRepository } from 'typeorm'
|
|
2
|
-
import { Oauth2Client } from '../../../entities'
|
|
3
|
-
|
|
4
|
-
export const deleteOauth2Client = {
|
|
5
|
-
async deleteOauth2Client(_: any, { id }, context: any) {
|
|
6
|
-
await getRepository(Oauth2Client).delete({ domain: context.state.domain, id })
|
|
7
|
-
return true
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { getRepository, In } from 'typeorm'
|
|
2
|
-
import { Oauth2Client } from '../../../entities'
|
|
3
|
-
|
|
4
|
-
export const deleteOauth2Clients = {
|
|
5
|
-
async deleteOauth2Clients(_: any, { ids }, context: any) {
|
|
6
|
-
await getRepository(Oauth2Client).delete({
|
|
7
|
-
domain: context.state.domain,
|
|
8
|
-
id: In(ids)
|
|
9
|
-
})
|
|
10
|
-
return true
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import ClientOAuth2 from 'client-oauth2'
|
|
2
|
-
import { getRepository } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { Oauth2Client } from '../../../entities'
|
|
5
|
-
|
|
6
|
-
export const getOauth2AccessToken = {
|
|
7
|
-
async getOauth2AccessToken(_: any, { id }, context: any) {
|
|
8
|
-
const repository = getRepository(Oauth2Client)
|
|
9
|
-
const oauth2Client = await repository.findOne(id)
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
grantType,
|
|
13
|
-
clientId,
|
|
14
|
-
clientSecret,
|
|
15
|
-
accessTokenUrl: accessTokenUri,
|
|
16
|
-
authUrl: authorizationUri,
|
|
17
|
-
username,
|
|
18
|
-
password,
|
|
19
|
-
jwtToken,
|
|
20
|
-
scopes
|
|
21
|
-
} = oauth2Client
|
|
22
|
-
|
|
23
|
-
var auth = new ClientOAuth2({
|
|
24
|
-
clientId,
|
|
25
|
-
clientSecret,
|
|
26
|
-
accessTokenUri,
|
|
27
|
-
authorizationUri,
|
|
28
|
-
scopes: scopes.split(' ')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
var getTokenParams = []
|
|
32
|
-
switch (grantType) {
|
|
33
|
-
case 'owner':
|
|
34
|
-
getTokenParams = [username, password]
|
|
35
|
-
break
|
|
36
|
-
case 'credentials':
|
|
37
|
-
getTokenParams = []
|
|
38
|
-
break
|
|
39
|
-
case 'jwt':
|
|
40
|
-
getTokenParams = [jwtToken]
|
|
41
|
-
break
|
|
42
|
-
case 'code':
|
|
43
|
-
default:
|
|
44
|
-
throw new Error(`unsupported grant type: ${grantType}`)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const token = await auth[grantType].getToken.call(auth[grantType], getTokenParams)
|
|
48
|
-
const { tokenType: newTokenType, accessToken, refreshToken, data } = token
|
|
49
|
-
const expires = data?.expires_in ? token.expiresIn(data?.expires_in as any) : null
|
|
50
|
-
|
|
51
|
-
return await repository.save({
|
|
52
|
-
...oauth2Client,
|
|
53
|
-
tokenType: newTokenType,
|
|
54
|
-
accessToken,
|
|
55
|
-
refreshToken,
|
|
56
|
-
expires
|
|
57
|
-
// state: ''
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Query } from './oauth2-client-query'
|
|
2
|
-
|
|
3
|
-
import { updateOauth2Client } from './update-oauth2-client'
|
|
4
|
-
import { createOauth2Client } from './create-oauth2-client'
|
|
5
|
-
import { deleteOauth2Client } from './delete-oauth2-client'
|
|
6
|
-
import { deleteOauth2Clients } from './delete-oauth2-clients'
|
|
7
|
-
|
|
8
|
-
import { getOauth2AccessToken } from './get-oauth2-access-token'
|
|
9
|
-
import { refreshOauth2AccessToken } from './refresh-oauth2-access-token'
|
|
10
|
-
|
|
11
|
-
export const Oauth2ClientResolver = {
|
|
12
|
-
Query,
|
|
13
|
-
Mutation: {
|
|
14
|
-
...updateOauth2Client,
|
|
15
|
-
...createOauth2Client,
|
|
16
|
-
...deleteOauth2Client,
|
|
17
|
-
...deleteOauth2Clients,
|
|
18
|
-
...getOauth2AccessToken,
|
|
19
|
-
...refreshOauth2AccessToken
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { ListParam, convertListParams } from '@things-factory/shell'
|
|
2
|
-
import ClientOAuth2 from 'client-oauth2'
|
|
3
|
-
import { getRepository } from 'typeorm'
|
|
4
|
-
import crypto from 'crypto'
|
|
5
|
-
import { Oauth2Client } from '../../../entities'
|
|
6
|
-
|
|
7
|
-
export const Query = {
|
|
8
|
-
async oauth2Client(_: any, { id }, context: any) {
|
|
9
|
-
const repository = getRepository(Oauth2Client)
|
|
10
|
-
|
|
11
|
-
return await repository.findOne({
|
|
12
|
-
where: { domain: context.state.domain, id },
|
|
13
|
-
relations: ['domain', 'creator', 'updater']
|
|
14
|
-
})
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
async oauth2Clients(_: any, params: ListParam, context: any) {
|
|
18
|
-
const convertedParams = convertListParams(params)
|
|
19
|
-
const [items, total] = await getRepository(Oauth2Client).findAndCount({
|
|
20
|
-
...convertedParams,
|
|
21
|
-
relations: ['domain', 'creator', 'updater']
|
|
22
|
-
})
|
|
23
|
-
return { items, total }
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
async getOauth2AuthUrl(_: any, { id }, context: any) {
|
|
27
|
-
const repository = getRepository(Oauth2Client)
|
|
28
|
-
const oauth2Client = await repository.findOne(id)
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
grantType,
|
|
32
|
-
clientId,
|
|
33
|
-
clientSecret,
|
|
34
|
-
callbackUrl,
|
|
35
|
-
accessTokenUrl: accessTokenUri,
|
|
36
|
-
authUrl: authorizationUri,
|
|
37
|
-
scopes
|
|
38
|
-
} = oauth2Client
|
|
39
|
-
|
|
40
|
-
if (grantType !== 'code') {
|
|
41
|
-
throw new Error(`unsupported grant type: ${grantType}`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const state = crypto.randomBytes(16).toString('hex')
|
|
45
|
-
await repository.save({
|
|
46
|
-
...oauth2Client,
|
|
47
|
-
state
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
var auth = new ClientOAuth2({
|
|
51
|
-
clientId,
|
|
52
|
-
clientSecret,
|
|
53
|
-
accessTokenUri,
|
|
54
|
-
authorizationUri,
|
|
55
|
-
redirectUri: callbackUrl || `${context.origin}/oauth2-client/callback`,
|
|
56
|
-
scopes: scopes?.split(' ') || [],
|
|
57
|
-
state
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
return await (auth[grantType] as any).getUri()
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import ClientOAuth2 from 'client-oauth2'
|
|
2
|
-
import { getRepository } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { Oauth2Client } from '../../../entities'
|
|
5
|
-
|
|
6
|
-
export const refreshOauth2AccessToken = {
|
|
7
|
-
async refreshOauth2AccessToken(_: any, { id }, context: any) {
|
|
8
|
-
const repository = getRepository(Oauth2Client)
|
|
9
|
-
const oauth2Client = await repository.findOne(id)
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
clientId,
|
|
13
|
-
clientSecret,
|
|
14
|
-
accessTokenUrl: accessTokenUri,
|
|
15
|
-
authUrl: authorizationUri,
|
|
16
|
-
scopes,
|
|
17
|
-
tokenType,
|
|
18
|
-
accessToken,
|
|
19
|
-
refreshToken
|
|
20
|
-
} = oauth2Client
|
|
21
|
-
|
|
22
|
-
if (!refreshToken) {
|
|
23
|
-
throw new Error('refreshToken not found')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var auth = new ClientOAuth2({
|
|
27
|
-
clientId,
|
|
28
|
-
clientSecret,
|
|
29
|
-
accessTokenUri,
|
|
30
|
-
authorizationUri,
|
|
31
|
-
scopes: scopes?.split(' ')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
var token = await auth.createToken(accessToken, refreshToken, tokenType, {}).refresh()
|
|
36
|
-
} catch (err) {
|
|
37
|
-
throw err
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const { accessToken: newAccessToken, refreshToken: newRefreshToken, tokenType: newTokenType, data } = token
|
|
41
|
-
const expires = data?.expires_in ? token.expiresIn(data?.expires_in as any) : null
|
|
42
|
-
|
|
43
|
-
return await repository.save({
|
|
44
|
-
...oauth2Client,
|
|
45
|
-
accessToken: newAccessToken,
|
|
46
|
-
refreshToken: newRefreshToken,
|
|
47
|
-
tokenType: newTokenType,
|
|
48
|
-
expires
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getRepository } from 'typeorm'
|
|
2
|
-
import { Oauth2Client } from '../../../entities'
|
|
3
|
-
|
|
4
|
-
export const updateOauth2Client = {
|
|
5
|
-
async updateOauth2Client(_: any, { id, patch }, context: any) {
|
|
6
|
-
const repository = getRepository(Oauth2Client)
|
|
7
|
-
const oauth2Client = await repository.findOne({
|
|
8
|
-
where: { domain: context.state.domain, id }
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
return await repository.save({
|
|
12
|
-
...oauth2Client,
|
|
13
|
-
...patch,
|
|
14
|
-
updater: context.state.user
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './oauth2-client'
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
|
|
3
|
-
export * from './oauth2-client'
|
|
4
|
-
export * from './new-oauth2-client'
|
|
5
|
-
export * from './oauth2-client-patch'
|
|
6
|
-
export * from './oauth2-client-list'
|
|
7
|
-
|
|
8
|
-
export const Oauth2ClientResolver = gql`
|
|
9
|
-
extend type Mutation {
|
|
10
|
-
createOauth2Client(oauth2Client: NewOauth2Client!): Oauth2Client
|
|
11
|
-
updateOauth2Client(id: String!, patch: Oauth2ClientPatch!): Oauth2Client
|
|
12
|
-
deleteOauth2Client(id: String!): Boolean
|
|
13
|
-
deleteOauth2Clients(ids: [String]!): Boolean
|
|
14
|
-
getOauth2AccessToken(id: String!): Oauth2Client
|
|
15
|
-
refreshOauth2AccessToken(id: String!): Oauth2Client
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
extend type Query {
|
|
19
|
-
oauth2Clients(filters: [Filter], pagination: Pagination, sortings: [Sorting]): Oauth2ClientList
|
|
20
|
-
oauth2Client(id: String!): Oauth2Client
|
|
21
|
-
getOauth2AuthUrl(id: String!): String
|
|
22
|
-
}
|
|
23
|
-
`
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
|
|
3
|
-
export const NewOauth2Client = gql`
|
|
4
|
-
input NewOauth2Client {
|
|
5
|
-
name: String
|
|
6
|
-
description: String
|
|
7
|
-
icon: String
|
|
8
|
-
grantType: String
|
|
9
|
-
clientId: String
|
|
10
|
-
clientSecret: String
|
|
11
|
-
callbackUrl: String
|
|
12
|
-
authUrl: String
|
|
13
|
-
accessTokenUrl: String
|
|
14
|
-
webhook: String
|
|
15
|
-
username: String
|
|
16
|
-
password: String
|
|
17
|
-
codeChallengeMethod: String
|
|
18
|
-
codeVerifier: String
|
|
19
|
-
scopes: String
|
|
20
|
-
accessToken: String
|
|
21
|
-
refreshToken: String
|
|
22
|
-
jwtToken: String
|
|
23
|
-
}
|
|
24
|
-
`
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
|
|
3
|
-
export const Oauth2ClientPatch = gql`
|
|
4
|
-
input Oauth2ClientPatch {
|
|
5
|
-
name: String
|
|
6
|
-
description: String
|
|
7
|
-
icon: String
|
|
8
|
-
grantType: String
|
|
9
|
-
clientId: String
|
|
10
|
-
clientSecret: String
|
|
11
|
-
callbackUrl: String
|
|
12
|
-
authUrl: String
|
|
13
|
-
accessTokenUrl: String
|
|
14
|
-
webhook: String
|
|
15
|
-
username: String
|
|
16
|
-
password: String
|
|
17
|
-
codeChallengeMethod: String
|
|
18
|
-
codeVerifier: String
|
|
19
|
-
scopes: String
|
|
20
|
-
accessToken: String
|
|
21
|
-
refreshToken: String
|
|
22
|
-
jwtToken: String
|
|
23
|
-
}
|
|
24
|
-
`
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
|
|
3
|
-
export const Oauth2Client = gql`
|
|
4
|
-
type Oauth2Client {
|
|
5
|
-
id: String
|
|
6
|
-
domain: Domain
|
|
7
|
-
name: String
|
|
8
|
-
description: String
|
|
9
|
-
icon: String
|
|
10
|
-
grantType: String
|
|
11
|
-
clientId: String
|
|
12
|
-
clientSecret: String
|
|
13
|
-
callbackUrl: String
|
|
14
|
-
authUrl: String
|
|
15
|
-
accessTokenUrl: String
|
|
16
|
-
webhook: String
|
|
17
|
-
username: String
|
|
18
|
-
password: String
|
|
19
|
-
codeChallengeMethod: String
|
|
20
|
-
codeVerifier: String
|
|
21
|
-
scopes: String
|
|
22
|
-
accessToken: String
|
|
23
|
-
refreshToken: String
|
|
24
|
-
expires: String
|
|
25
|
-
jwtToken: String
|
|
26
|
-
tokenType: String
|
|
27
|
-
updater: User
|
|
28
|
-
creator: User
|
|
29
|
-
updatedAt: String
|
|
30
|
-
createdAt: String
|
|
31
|
-
}
|
|
32
|
-
`
|