@things-factory/oauth2-client 9.1.13 → 10.0.0-beta.1

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.
@@ -6,10 +6,9 @@ import gql from 'graphql-tag';
6
6
  import { css, html } from 'lit';
7
7
  import { customElement, property, query, queryAll } from 'lit/decorators.js';
8
8
  import { asyncReplace } from 'lit/directives/async-replace.js';
9
- import { connect } from 'pwa-helpers/connect-mixin.js';
10
9
  import { client } from '@operato/graphql';
11
10
  import { notify } from '@operato/layout';
12
- import { navigate, PageView, store } from '@operato/shell';
11
+ import { navigate, PageView } from '@operato/shell';
13
12
  import { sleep } from '@operato/utils';
14
13
  const OAUTH2CLIENT = `
15
14
  id
@@ -36,45 +35,39 @@ tokenType
36
35
  updatedAt
37
36
  createdAt
38
37
  `;
39
- let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
38
+ let Oauth2Client = class Oauth2Client extends PageView {
40
39
  static { this.styles = [
41
40
  css `
42
- :host {
43
- display: flex;
41
+ :host { display: flex;
44
42
  flex-direction: column;
45
43
  overflow-y: auto;
46
44
  position: relative;
47
45
 
48
46
  background-color: var(--md-sys-color-background);
49
47
  padding: var(--spacing-large);
50
- }
48
+ }
51
49
 
52
- h2 {
53
- margin: var(--title-margin);
50
+ h2 { margin: var(--title-margin);
54
51
  font: var(--title-font);
55
52
  color: var(--title-text-color);
56
- }
53
+ }
57
54
 
58
- [page-description] {
59
- margin: var(--page-description-margin);
55
+ [page-description] { margin: var(--page-description-margin);
60
56
  font: var(--page-description-font);
61
57
  color: var(--page-description-color);
62
- }
58
+ }
63
59
 
64
- [icon] {
65
- position: absolute;
60
+ [icon] { position: absolute;
66
61
  top: 10px;
67
62
  right: 10px;
68
63
  max-width: 80px;
69
- }
64
+ }
70
65
 
71
- [icon] img {
72
- max-width: 100%;
66
+ [icon] img { max-width: 100%;
73
67
  max-height: 100%;
74
- }
68
+ }
75
69
 
76
- [button-primary] {
77
- background-color: var(--button-primary-background-color);
70
+ [button-primary] { background-color: var(--button-primary-background-color);
78
71
  border: var(--button-border);
79
72
  border-radius: var(--button-border-radius);
80
73
  margin: var(--button-margin);
@@ -84,92 +77,78 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
84
77
  text-transform: var(--button-text-transform);
85
78
 
86
79
  text-decoration: none;
87
- }
80
+ }
88
81
 
89
- [button-primary]:hover {
90
- background-color: var(--button-primary-active-background-color);
82
+ [button-primary]:hover { background-color: var(--button-primary-active-background-color);
91
83
  box-shadow: var(--button-active-box-shadow);
92
- }
84
+ }
93
85
 
94
- [fieldset-container] {
95
- background-color: var(--md-sys-color-surface);
86
+ [fieldset-container] { background-color: var(--md-sys-color-surface);
96
87
  margin: var(--spacing-large) 0 var(--spacing-medium) 0;
97
88
  padding: var(--spacing-medium);
98
89
  border-radius: var(--border-radius);
99
90
  box-shadow: var(--box-shadow);
100
91
 
101
- label {
102
- font: var(--label-font);
92
+ label { font: var(--label-font);
103
93
  color: var(--label-color, var(--md-sys-color-on-surface));
104
94
  text-transform: var(--label-text-transform);
105
- }
95
+ }
106
96
 
107
97
  input,
108
- select {
109
- border: var(--border-dim-color);
98
+ select { border: var(--border-dim-color);
110
99
  border-radius: var(--border-radius);
111
100
  margin: var(--input-margin);
112
101
  padding: var(--input-padding);
113
102
  font: var(--input-font);
114
103
 
115
104
  flex: 1;
116
- }
105
+ }
117
106
 
118
107
  select:focus,
119
108
  input:focus,
120
- button {
121
- outline: none;
122
- }
109
+ button { outline: none;
110
+ }
123
111
 
124
- form {
125
- max-width: var(--content-container-max-width);
126
- }
127
- }
112
+ form { max-width: var(--content-container-max-width);
113
+ }
114
+ }
128
115
 
129
- [fieldset-container] fieldset {
130
- margin: 0;
116
+ [fieldset-container] fieldset { margin: 0;
131
117
  margin-top: -15px;
132
- }
118
+ }
133
119
 
134
- fieldset {
135
- border-radius: var(--border-radius);
120
+ fieldset { border-radius: var(--border-radius);
136
121
  border: var(--border-dim-color);
137
122
  margin: var(--fieldset-margin);
138
123
  padding: var(--fieldset-padding);
139
- }
124
+ }
140
125
 
141
- legend {
142
- padding: var(--legend-padding);
126
+ legend { padding: var(--legend-padding);
143
127
  font-weight: bold;
144
128
  color: var(--legend-color);
145
- }
129
+ }
146
130
 
147
- [field-2column] {
148
- display: grid;
131
+ [field-2column] { display: grid;
149
132
  grid-template-columns: 1fr 1fr;
150
133
  grid-gap: 15px;
151
- }
134
+ }
152
135
 
153
- [field] {
154
- display: flex;
136
+ [field] { display: flex;
155
137
  flex-direction: column;
156
138
  position: relative;
157
- }
139
+ }
158
140
 
159
- [grid-span] {
160
- grid-column: span 2;
161
- }
141
+ [grid-span] { grid-column: span 2;
142
+ }
162
143
 
163
- button {
164
- display: flex;
144
+ button { display: flex;
165
145
  align-items: center;
166
146
  gap: var(--spacing-small);
167
- }
147
+ }
168
148
 
169
149
  button,
170
150
  input[type='submit'],
171
- [button-in-field] {
172
- background-color: var(--button-background-color);
151
+ [button-in-field] { background-color: var(--button-background-color);
173
152
  border: var(--button-border);
174
153
  border-radius: var(--button-border-radius);
175
154
  padding: var(--button-padding);
@@ -180,38 +159,31 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
180
159
  margin: var(--spacing-medium) 0 var(--spacing-medium) var(--spacing-medium);
181
160
  float: right;
182
161
  text-decoration: none;
183
- }
162
+ }
184
163
 
185
164
  button:hover,
186
- input[type='submit']:hover {
187
- border: var(--button-activ-border);
165
+ input[type='submit']:hover { border: var(--button-activ-border);
188
166
  box-shadow: var(--button-active-box-shadow);
189
- }
167
+ }
190
168
 
191
- [button-in-field] {
192
- border-radius: 0 var(--button-border-radius) var(--button-border-radius) 0;
169
+ [button-in-field] { border-radius: 0 var(--button-border-radius) var(--button-border-radius) 0;
193
170
  position: absolute;
194
171
  top: 12px;
195
172
  right: 0;
196
173
  max-height: 36px;
197
- }
174
+ }
198
175
 
199
- [input-hint] {
200
- font: var(--input-hint-font);
176
+ [input-hint] { font: var(--input-hint-font);
201
177
  color: var(--input-hint-color);
202
- }
178
+ }
203
179
 
204
- @media screen and (max-width: 480px) {
205
- [field] {
206
- grid-column: span 2;
207
- }
208
- }
180
+ @media screen and (max-width: 480px) { [field] { grid-column: span 2;
181
+ }
182
+ }
209
183
  `
210
184
  ]; }
211
185
  get context() {
212
- return {
213
- title: {
214
- icon: 'apps',
186
+ return { title: { icon: 'apps',
215
187
  text: this.oauth2Client?.name
216
188
  }
217
189
  };
@@ -414,8 +386,7 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
414
386
  }
415
387
  }
416
388
  firstUpdated() {
417
- this.clipboard = new Clipboard(this.copybuttons, {
418
- target: (trigger => trigger.parentElement.querySelector('input'))
389
+ this.clipboard = new Clipboard(this.copybuttons, { target: (trigger => trigger.parentElement.querySelector('input'))
419
390
  });
420
391
  }
421
392
  async pageUpdated(changes, lifecycle, before) {
@@ -440,16 +411,12 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
440
411
  }
441
412
  }
442
413
  async fetchOauth2Client() {
443
- const response = await client.query({
444
- query: gql `
445
- query($id: String!) {
446
- oauth2Client(id: $id) {
447
- ${OAUTH2CLIENT}
448
- }
449
- }
414
+ const response = await client.query({ query: gql `
415
+ query($id: String!) { oauth2Client(id: $id) { ${OAUTH2CLIENT}
416
+ }
417
+ }
450
418
  `,
451
- variables: {
452
- id: this.lifecycle.resourceId
419
+ variables: { id: this.lifecycle.resourceId
453
420
  }
454
421
  });
455
422
  this.oauth2Client = response.data.oauth2Client;
@@ -461,22 +428,17 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
461
428
  return patch;
462
429
  }, {});
463
430
  const id = this.lifecycle.resourceId;
464
- const response = await client.mutate({
465
- mutation: gql `
466
- mutation($id: String!, $patch: Oauth2ClientPatch!) {
467
- updateOauth2Client(id: $id, patch: $patch) {
468
- ${OAUTH2CLIENT}
469
- }
470
- }
431
+ const response = await client.mutate({ mutation: gql `
432
+ mutation($id: String!, $patch: Oauth2ClientPatch!) { updateOauth2Client(id: $id, patch: $patch) { ${OAUTH2CLIENT}
433
+ }
434
+ }
471
435
  `,
472
- variables: {
473
- id,
436
+ variables: { id,
474
437
  patch
475
438
  }
476
439
  });
477
440
  if (response.errors) {
478
- notify({
479
- level: 'error',
441
+ notify({ level: 'error',
480
442
  message: 'update oauth2 client fail'
481
443
  });
482
444
  }
@@ -487,19 +449,15 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
487
449
  async deleteOauth2Client(e) {
488
450
  e.preventDefault();
489
451
  const id = this.lifecycle.resourceId;
490
- const response = await client.mutate({
491
- mutation: gql `
492
- mutation ($id: String!) {
493
- deleteOauth2Client(id: $id)
494
- }
452
+ const response = await client.mutate({ mutation: gql `
453
+ mutation ($id: String!) { deleteOauth2Client(id: $id)
454
+ }
495
455
  `,
496
- variables: {
497
- id
456
+ variables: { id
498
457
  }
499
458
  });
500
459
  if (response.errors) {
501
- notify({
502
- level: 'error',
460
+ notify({ level: 'error',
503
461
  message: 'delete oauth2 client fail'
504
462
  });
505
463
  }
@@ -510,49 +468,39 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
510
468
  async generateOauth2AccessToken() {
511
469
  const id = this.lifecycle.resourceId;
512
470
  if (this.oauth2Client.grantType == 'code') {
513
- const response = await client.mutate({
514
- mutation: gql `
515
- mutation ($id: String!) {
516
- getOauth2AuthUrl(id: $id)
517
- }
471
+ const response = await client.mutate({ mutation: gql `
472
+ mutation ($id: String!) { getOauth2AuthUrl(id: $id)
473
+ }
518
474
  `,
519
- variables: {
520
- id: this.lifecycle.resourceId
475
+ variables: { id: this.lifecycle.resourceId
521
476
  }
522
477
  });
523
478
  if (!response.errors) {
524
479
  location.href = response.data.getOauth2AuthUrl;
525
480
  }
526
481
  else {
527
- notify({
528
- level: 'error',
482
+ notify({ level: 'error',
529
483
  message: 'getting application access token fail'
530
484
  });
531
485
  }
532
486
  }
533
487
  else {
534
- const response = await client.mutate({
535
- mutation: gql `
536
- mutation($id: String!) {
537
- getOauth2AccessToken(id: $id) {
538
- ${OAUTH2CLIENT}
539
- }
540
- }
488
+ const response = await client.mutate({ mutation: gql `
489
+ mutation($id: String!) { getOauth2AccessToken(id: $id) { ${OAUTH2CLIENT}
490
+ }
491
+ }
541
492
  `,
542
- variables: {
543
- id: this.lifecycle.resourceId
493
+ variables: { id: this.lifecycle.resourceId
544
494
  }
545
495
  });
546
496
  if (response.errors) {
547
- notify({
548
- level: 'error',
497
+ notify({ level: 'error',
549
498
  message: 'getting application access token fail'
550
499
  });
551
500
  }
552
501
  else {
553
502
  this.oauth2Client = response.data.getOauth2AccessToken;
554
- notify({
555
- level: 'info',
503
+ notify({ level: 'info',
556
504
  message: 'got application access token successfully'
557
505
  });
558
506
  }
@@ -560,28 +508,22 @@ let Oauth2Client = class Oauth2Client extends connect(store)(PageView) {
560
508
  }
561
509
  async refreshOauth2AccessToken() {
562
510
  const id = this.lifecycle.resourceId;
563
- const response = await client.mutate({
564
- mutation: gql `
565
- mutation($id: String!) {
566
- refreshOauth2AccessToken(id: $id) {
567
- ${OAUTH2CLIENT}
568
- }
569
- }
511
+ const response = await client.mutate({ mutation: gql `
512
+ mutation($id: String!) { refreshOauth2AccessToken(id: $id) { ${OAUTH2CLIENT}
513
+ }
514
+ }
570
515
  `,
571
- variables: {
572
- id: this.lifecycle.resourceId
516
+ variables: { id: this.lifecycle.resourceId
573
517
  }
574
518
  });
575
519
  if (response.errors) {
576
- notify({
577
- level: 'error',
520
+ notify({ level: 'error',
578
521
  message: 'getting application access token fail'
579
522
  });
580
523
  }
581
524
  else {
582
525
  this.oauth2Client = response.data.refreshOauth2AccessToken;
583
- notify({
584
- level: 'info',
526
+ notify({ level: 'info',
585
527
  message: 'got application access token successfully'
586
528
  });
587
529
  }
@@ -1 +1 @@
1
- {"version":3,"file":"oauth2-client.js","sourceRoot":"","sources":["../../client/pages/oauth2-client.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,+BAA+B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AAC,MAAM,CAAC;8BAAQ,eAAe;0CAAA;AACP;IAA7B,QAAQ,CAAC,kBAAkB,CAAC;;iDAAY;AAjL9B,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CAilBxB","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@operato/help/ox-help-icon.js'\n\nimport Clipboard from 'clipboard'\nimport gql from 'graphql-tag'\nimport { css, html } from 'lit'\nimport { customElement, property, query, queryAll } from 'lit/decorators.js'\nimport { asyncReplace } from 'lit/directives/async-replace.js'\nimport { connect } from 'pwa-helpers/connect-mixin.js'\n\nimport { client } from '@operato/graphql'\nimport { notify } from '@operato/layout'\nimport { navigate, PageView, store } from '@operato/shell'\nimport { sleep } from '@operato/utils'\n\nconst OAUTH2CLIENT = `\nid\nname\ndescription\nicon\ngrantType\nclientId\nclientSecret\ncallbackUrl\nauthUrl\naccessTokenUrl\nwebhook\nusername\npassword\ncodeChallengeMethod\ncodeVerifier\nscopes\naccessToken\nrefreshToken\njwtToken\nexpires\ntokenType\nupdatedAt\ncreatedAt\n`\n\n@customElement('oauth2-client')\nexport class Oauth2Client extends connect(store)(PageView) {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: column;\n overflow-y: auto;\n position: relative;\n\n background-color: var(--md-sys-color-background);\n padding: var(--spacing-large);\n }\n\n h2 {\n margin: var(--title-margin);\n font: var(--title-font);\n color: var(--title-text-color);\n }\n\n [page-description] {\n margin: var(--page-description-margin);\n font: var(--page-description-font);\n color: var(--page-description-color);\n }\n\n [icon] {\n position: absolute;\n top: 10px;\n right: 10px;\n max-width: 80px;\n }\n\n [icon] img {\n max-width: 100%;\n max-height: 100%;\n }\n\n [button-primary] {\n background-color: var(--button-primary-background-color);\n border: var(--button-border);\n border-radius: var(--button-border-radius);\n margin: var(--button-margin);\n padding: var(--button-primary-padding);\n color: var(--button-primary-color);\n font: var(--button-primary-font);\n text-transform: var(--button-text-transform);\n\n text-decoration: none;\n }\n\n [button-primary]:hover {\n background-color: var(--button-primary-active-background-color);\n box-shadow: var(--button-active-box-shadow);\n }\n\n [fieldset-container] {\n background-color: var(--md-sys-color-surface);\n margin: var(--spacing-large) 0 var(--spacing-medium) 0;\n padding: var(--spacing-medium);\n border-radius: var(--border-radius);\n box-shadow: var(--box-shadow);\n\n label {\n font: var(--label-font);\n color: var(--label-color, var(--md-sys-color-on-surface));\n text-transform: var(--label-text-transform);\n }\n\n input,\n select {\n border: var(--border-dim-color);\n border-radius: var(--border-radius);\n margin: var(--input-margin);\n padding: var(--input-padding);\n font: var(--input-font);\n\n flex: 1;\n }\n\n select:focus,\n input:focus,\n button {\n outline: none;\n }\n\n form {\n max-width: var(--content-container-max-width);\n }\n }\n\n [fieldset-container] fieldset {\n margin: 0;\n margin-top: -15px;\n }\n\n fieldset {\n border-radius: var(--border-radius);\n border: var(--border-dim-color);\n margin: var(--fieldset-margin);\n padding: var(--fieldset-padding);\n }\n\n legend {\n padding: var(--legend-padding);\n font-weight: bold;\n color: var(--legend-color);\n }\n\n [field-2column] {\n display: grid;\n grid-template-columns: 1fr 1fr;\n grid-gap: 15px;\n }\n\n [field] {\n display: flex;\n flex-direction: column;\n position: relative;\n }\n\n [grid-span] {\n grid-column: span 2;\n }\n\n button {\n display: flex;\n align-items: center;\n gap: var(--spacing-small);\n }\n\n button,\n input[type='submit'],\n [button-in-field] {\n background-color: var(--button-background-color);\n border: var(--button-border);\n border-radius: var(--button-border-radius);\n padding: var(--button-padding);\n color: var(--button-color);\n font: var(--button-font);\n text-transform: var(--button-text-transform);\n\n margin: var(--spacing-medium) 0 var(--spacing-medium) var(--spacing-medium);\n float: right;\n text-decoration: none;\n }\n\n button:hover,\n input[type='submit']:hover {\n border: var(--button-activ-border);\n box-shadow: var(--button-active-box-shadow);\n }\n\n [button-in-field] {\n border-radius: 0 var(--button-border-radius) var(--button-border-radius) 0;\n position: absolute;\n top: 12px;\n right: 0;\n max-height: 36px;\n }\n\n [input-hint] {\n font: var(--input-hint-font);\n color: var(--input-hint-color);\n }\n\n @media screen and (max-width: 480px) {\n [field] {\n grid-column: span 2;\n }\n }\n `\n ]\n\n @property({ type: Object }) oauth2Client: any\n @property({ type: String }) _grantType?: string\n\n @query('form') form!: HTMLFormElement\n @queryAll('[clipboard-copy]') copybuttons\n\n private clipboard?: Clipboard\n private _icon?: string\n\n get context() {\n return {\n title: {\n icon: 'apps',\n text: this.oauth2Client?.name\n }\n }\n }\n\n render() {\n var oauth2Client = this.oauth2Client || {}\n\n return html`\n <div>\n <h2><md-icon>apps</md-icon>&nbsp;${oauth2Client.name || ''}</h2>\n <p page-description>${oauth2Client.description || ''}</p>\n </div>\n\n <div icon>\n <img src=${oauth2Client.icon}>\n </div>\n\n <form>\n <div fieldset-container>\n <fieldset>\n <legend>oauth2 client</legend>\n <div field-2column>\n <div field grid-span>\n <label for='name'>name</label>\n <input type='text' id=\"name\" name=\"name\" .value=${oauth2Client.name || ''}>\n </div>\n\n <div field grid-span>\n <label for='description'>description</label>\n <input type='text' id=\"description\" name=\"description\" .value=${oauth2Client.description || ''}>\n </div>\n\n <div field grid-span>\n <label for='icon'>icon</label>\n <input type='text' id=\"icon\" name=\"icon\" \n @change=${e => (this._icon = e.target.value)} \n .value=${oauth2Client.icon || ''}\n >\n </div>\n </div>\n </fieldset>\n </div>\n\n <div fieldset-container>\n <fieldset>\n <legend>authorization</legend>\n <div field-2column>\n <div field grid-span>\n <label for='grant-type'>grant type\n <ox-help-icon topic='/oauth2-client/grant-type'></ox-help-icon>\n </label>\n <select type='text' id=\"grant-type\" name=\"grantType\" .value=${oauth2Client.grantType || 'code'} \n @change=${e => (this._grantType = e.target.value)}>\n <option></option>\n <option value='code'>Authorization Code Grant</option>\n <option value='jwt'>JWT As Authorization Grant</option>\n <option value='owner'>Resource Owner Password Credentials Grant</option>\n <option value='credentials'>Client Credentials Grant</option>\n </select>\n </div>\n\n <div field grid-span>\n <label for='auth-url'>auth url</label>\n <input type='text' id=\"auth-url\" name=\"authUrl\" .value=${oauth2Client.authUrl || ''}>\n <div input-hint>The endpoint for authorization server. This is used to get the authorization code.</div>\n </div>\n\n <div field grid-span>\n <label for='access-token-url'>access token url</label>\n <input type='text' id=\"access-token-url\" name=\"accessTokenUrl\" .value=${\n oauth2Client.accessTokenUrl || ''\n }>\n <div input-hint>The endpoint for authentication server. This is used to exchange the authorization code for an access token.</div>\n </div>\n\n <div field grid-span>\n <label for='callback-url'>callback url</label>\n <input type='text' id=\"callback-url\" name=\"callbackUrl\" .value=${oauth2Client.callbackUrl || ''}>\n <div input-hint>This is the callback url that you will be redirected to, after your application is authorized.\n This is used to extract the authorization code or access token.\n Normally, this callback url should match the one you use during the application registration process.\n If you leave this field empty, default callback url(${\n location.origin\n }/oauth2-client/callback</label>) will be used.</div>\n </div>\n \n <div field grid-span>\n <label for='client-id'>client id</label>\n <input type='text' id=\"client-id\" name=\"clientId\" .value=${oauth2Client.clientId || ''}>\n <div input-hint>The client identifier issued to the client during the application registration process.</div>\n </div>\n\n <div field grid-span>\n <label for='client-secret'>client secret</label>\n <input type='text' id=\"client-secret\" name=\"clientSecret\" .value=${oauth2Client.clientSecret || ''}>\n <div input-hint>The client secret issued to the client during the application registration process.</div>\n </div>\n\n ${\n this._grantType == 'owner'\n ? html`\n <div field grid-span>\n <label for=\"username\">user name</label>\n <input type=\"text\" id=\"username\" name=\"username\" .value=${oauth2Client.username || ''} />\n </div>\n\n <div field grid-span>\n <label for=\"password\">password</label>\n <input type=\"password\" id=\"password\" name=\"password\" .value=${oauth2Client.password || ''} />\n </div>\n `\n : html``\n }\n\n ${\n this._grantType == 'jwt'\n ? html`\n <div field grid-span>\n <label for=\"jwt-token\">jwt-token</label>\n <input type=\"text\" id=\"jwt-token\" name=\"jwtToken\" .value=${oauth2Client.jwtToken || ''} />\n <div input-hint>The JWT Bearer Token for JWT As Authorization Grant</div>\n </div>\n `\n : html``\n }\n\n <!-- code PKCE grant type not supported yet\n <div field grid-span>\n <label for='code-challenge-method'>code challenge method</label>\n <select type='text' id=\"code-challenge-method\" name=\"codeChallengeMethod\" .value=${\n oauth2Client.codeChallengeMethod\n }>\n <option></option>\n <option>SHA-256</option>\n <option>Plain</option>\n </select>\n <div input-hint>Algorithm used for generating the code challenge</div>\n </div>\n\n <div field grid-span>\n <label for='code-verifier'>code verifier\n <ox-help-icon topic='/oauth2-client/code-verifier'></ox-help-icon>\n </label>\n <input type='text' id=\"code-verifier\" name=\"codeVerifier\" .value=${oauth2Client.codeVerifier || ''}>\n <div input-hint>A random, 43-128 character string used to connect the authorization request to the token request.\n Uses the following characters: [A-Z]/[a-z]/[0-9]/\"-\"/\".\"/\"_\"/\"~\".</div>\n </div>\n -->\n \n <div field grid-span>\n <label for='scopes'>scopes</label>\n <input type='text' id=\"scopes\" name=\"scopes\" .value=${oauth2Client.scopes || ''}>\n <div input-hint>The scopes of the access request. It may have multiple space-delimited values.</div>\n </div>\n </div>\n </fieldset>\n </div>\n\n <div fieldset-container>\n <fieldset>\n <div field grid-span>\n <label for='token-type'>token type</label>\n <input type='text' id=\"token-type\" .value=${oauth2Client.tokenType || ''} readonly>\n <div input-hint>Added to the authorization header before the access token.</div>\n </div>\n\n <legend>access token</legend>\n <div field-2column>\n <div field grid-span>\n <label for=\"access-token\">access token</label>\n <input id=\"access-token\" type=\"text\" .value=${oauth2Client.accessToken || ''} readonly />\n <button button-in-field clipboard-copy @click=${e => e.preventDefault()}>copy</button>\n ${\n oauth2Client.expires\n ? html`<div input-hint>\n expired in ${new Date(Number(oauth2Client.expires))} :\n ${asyncReplace(this.expTimer(oauth2Client.expires))}\n </div>`\n : html``\n }\n </div>\n\n <div field grid-span>\n <label for=\"refresh-token\">refresh token</label>\n <input id=\"refresh-token\" type=\"text\" .value=${oauth2Client.refreshToken || ''} readonly />\n <button button-in-field clipboard-copy @click=${e => e.preventDefault()}>copy</button>\n </div>\n </div>\n </fieldset>\n </div>\n\n <button @click=${e => this.deleteOauth2Client(e)}>delete this app</button>\n <button @click=${async e => {\n e.preventDefault()\n await this.updateOauth2Client()\n await this.generateOauth2AccessToken()\n }}>get new access token</button>\n <button @click=${async e => {\n e.preventDefault()\n await this.updateOauth2Client()\n await this.refreshOauth2AccessToken()\n }} ?disabled=${!oauth2Client.refreshToken}>refresh access token</button>\n <input type=\"submit\" value=\"update\" @click=${async e => {\n e.preventDefault()\n await this.updateOauth2Client()\n }}>\n </form>\n `\n }\n\n updated(changes) {\n if (changes.has('oauth2Client')) {\n this._grantType = this.oauth2Client?.grantType\n }\n }\n\n firstUpdated() {\n this.clipboard = new Clipboard(this.copybuttons, {\n target: (trigger => trigger.parentElement.querySelector('input')) as any\n })\n }\n\n async pageUpdated(changes, lifecycle, before) {\n if (this.active) {\n await this.fetchOauth2Client()\n }\n }\n\n async *expTimer(exp) {\n const DAY = 24 * 60 * 60\n const HOUR = 60 * 60\n const MIN = 60\n\n while (this.active) {\n var remain = Math.floor((Number(exp) - Date.now()) / 1000)\n const days = Math.floor(remain / DAY)\n remain -= days * DAY\n const hours = Math.floor(remain / HOUR)\n remain -= hours * HOUR\n const mins = Math.floor(remain / MIN)\n const secs = remain - mins * MIN\n\n yield `${days} days ${hours} hours ${mins} mins ${secs} seconds remain`\n\n await sleep(1000)\n }\n }\n\n async fetchOauth2Client() {\n const response = await client.query({\n query: gql`\n query($id: String!) {\n oauth2Client(id: $id) {\n ${OAUTH2CLIENT}\n }\n }\n `,\n variables: {\n id: this.lifecycle.resourceId\n }\n })\n\n this.oauth2Client = response.data.oauth2Client\n }\n\n async updateOauth2Client() {\n const formData = new FormData(this.form)\n\n const patch = Array.from(formData.entries()).reduce((patch, [key, value]) => {\n patch[key] = value\n return patch\n }, {})\n\n const id = this.lifecycle.resourceId\n\n const response = await client.mutate({\n mutation: gql`\n mutation($id: String!, $patch: Oauth2ClientPatch!) {\n updateOauth2Client(id: $id, patch: $patch) {\n ${OAUTH2CLIENT}\n }\n }\n `,\n variables: {\n id,\n patch\n }\n })\n\n if (response.errors) {\n notify({\n level: 'error',\n message: 'update oauth2 client fail'\n })\n } else {\n this.oauth2Client = response.data.updateOauth2Client\n }\n }\n\n async deleteOauth2Client(e) {\n e.preventDefault()\n\n const id = this.lifecycle.resourceId\n\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n deleteOauth2Client(id: $id)\n }\n `,\n variables: {\n id\n }\n })\n\n if (response.errors) {\n notify({\n level: 'error',\n message: 'delete oauth2 client fail'\n })\n } else {\n navigate('oauth2-clients')\n }\n }\n\n async generateOauth2AccessToken() {\n const id = this.lifecycle.resourceId\n\n if (this.oauth2Client.grantType == 'code') {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n getOauth2AuthUrl(id: $id)\n }\n `,\n variables: {\n id: this.lifecycle.resourceId\n }\n })\n\n if (!response.errors) {\n location.href = response.data.getOauth2AuthUrl\n } else {\n notify({\n level: 'error',\n message: 'getting application access token fail'\n })\n }\n } else {\n const response = await client.mutate({\n mutation: gql`\n mutation($id: String!) {\n getOauth2AccessToken(id: $id) {\n ${OAUTH2CLIENT}\n }\n }\n `,\n variables: {\n id: this.lifecycle.resourceId\n }\n })\n\n if (response.errors) {\n notify({\n level: 'error',\n message: 'getting application access token fail'\n })\n } else {\n this.oauth2Client = response.data.getOauth2AccessToken\n notify({\n level: 'info',\n message: 'got application access token successfully'\n })\n }\n }\n }\n\n async refreshOauth2AccessToken() {\n const id = this.lifecycle.resourceId\n\n const response = await client.mutate({\n mutation: gql`\n mutation($id: String!) {\n refreshOauth2AccessToken(id: $id) {\n ${OAUTH2CLIENT}\n }\n }\n `,\n variables: {\n id: this.lifecycle.resourceId\n }\n })\n\n if (response.errors) {\n notify({\n level: 'error',\n message: 'getting application access token fail'\n })\n } else {\n this.oauth2Client = response.data.refreshOauth2AccessToken\n notify({\n level: 'info',\n message: 'got application access token successfully'\n })\n }\n }\n}\n"]}
1
+ {"version":3,"file":"oauth2-client.js","sourceRoot":"","sources":["../../client/pages/oauth2-client.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,O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C;;iDAAY;AAvJ9B,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CAmfxB","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@operato/help/ox-help-icon.js'\n\nimport Clipboard from 'clipboard'\nimport gql from 'graphql-tag'\nimport { css, html } from 'lit'\nimport { customElement, property, query, queryAll } from 'lit/decorators.js'\nimport { asyncReplace } from 'lit/directives/async-replace.js'\nimport { client } from '@operato/graphql'\nimport { notify } from '@operato/layout'\nimport { navigate, PageView } from '@operato/shell'\nimport { sleep } from '@operato/utils'\n\nconst OAUTH2CLIENT = `\nid\nname\ndescription\nicon\ngrantType\nclientId\nclientSecret\ncallbackUrl\nauthUrl\naccessTokenUrl\nwebhook\nusername\npassword\ncodeChallengeMethod\ncodeVerifier\nscopes\naccessToken\nrefreshToken\njwtToken\nexpires\ntokenType\nupdatedAt\ncreatedAt\n`\n\n@customElement('oauth2-client')\nexport class Oauth2Client extends PageView { static styles = [\n css`\n :host { display: flex;\n flex-direction: column;\n overflow-y: auto;\n position: relative;\n\n background-color: var(--md-sys-color-background);\n padding: var(--spacing-large);\n }\n\n h2 { margin: var(--title-margin);\n font: var(--title-font);\n color: var(--title-text-color);\n }\n\n [page-description] { margin: var(--page-description-margin);\n font: var(--page-description-font);\n color: var(--page-description-color);\n }\n\n [icon] { position: absolute;\n top: 10px;\n right: 10px;\n max-width: 80px;\n }\n\n [icon] img { max-width: 100%;\n max-height: 100%;\n }\n\n [button-primary] { background-color: var(--button-primary-background-color);\n border: var(--button-border);\n border-radius: var(--button-border-radius);\n margin: var(--button-margin);\n padding: var(--button-primary-padding);\n color: var(--button-primary-color);\n font: var(--button-primary-font);\n text-transform: var(--button-text-transform);\n\n text-decoration: none;\n }\n\n [button-primary]:hover { background-color: var(--button-primary-active-background-color);\n box-shadow: var(--button-active-box-shadow);\n }\n\n [fieldset-container] { background-color: var(--md-sys-color-surface);\n margin: var(--spacing-large) 0 var(--spacing-medium) 0;\n padding: var(--spacing-medium);\n border-radius: var(--border-radius);\n box-shadow: var(--box-shadow);\n\n label { font: var(--label-font);\n color: var(--label-color, var(--md-sys-color-on-surface));\n text-transform: var(--label-text-transform);\n }\n\n input,\n select { border: var(--border-dim-color);\n border-radius: var(--border-radius);\n margin: var(--input-margin);\n padding: var(--input-padding);\n font: var(--input-font);\n\n flex: 1;\n }\n\n select:focus,\n input:focus,\n button { outline: none;\n }\n\n form { max-width: var(--content-container-max-width);\n }\n }\n\n [fieldset-container] fieldset { margin: 0;\n margin-top: -15px;\n }\n\n fieldset { border-radius: var(--border-radius);\n border: var(--border-dim-color);\n margin: var(--fieldset-margin);\n padding: var(--fieldset-padding);\n }\n\n legend { padding: var(--legend-padding);\n font-weight: bold;\n color: var(--legend-color);\n }\n\n [field-2column] { display: grid;\n grid-template-columns: 1fr 1fr;\n grid-gap: 15px;\n }\n\n [field] { display: flex;\n flex-direction: column;\n position: relative;\n }\n\n [grid-span] { grid-column: span 2;\n }\n\n button { display: flex;\n align-items: center;\n gap: var(--spacing-small);\n }\n\n button,\n input[type='submit'],\n [button-in-field] { background-color: var(--button-background-color);\n border: var(--button-border);\n border-radius: var(--button-border-radius);\n padding: var(--button-padding);\n color: var(--button-color);\n font: var(--button-font);\n text-transform: var(--button-text-transform);\n\n margin: var(--spacing-medium) 0 var(--spacing-medium) var(--spacing-medium);\n float: right;\n text-decoration: none;\n }\n\n button:hover,\n input[type='submit']:hover { border: var(--button-activ-border);\n box-shadow: var(--button-active-box-shadow);\n }\n\n [button-in-field] { border-radius: 0 var(--button-border-radius) var(--button-border-radius) 0;\n position: absolute;\n top: 12px;\n right: 0;\n max-height: 36px;\n }\n\n [input-hint] { font: var(--input-hint-font);\n color: var(--input-hint-color);\n }\n\n @media screen and (max-width: 480px) { [field] { grid-column: span 2;\n }\n }\n `\n ]\n\n @property({ type: Object }) oauth2Client: any\n @property({ type: String }) _grantType?: string\n\n @query('form') form!: HTMLFormElement\n @queryAll('[clipboard-copy]') copybuttons\n\n private clipboard?: Clipboard\n private _icon?: string\n\n get context() { return { title: { icon: 'apps',\n text: this.oauth2Client?.name\n }\n }\n }\n\n render() { var oauth2Client = this.oauth2Client || {}\n\n return html`\n <div>\n <h2><md-icon>apps</md-icon>&nbsp;${oauth2Client.name || ''}</h2>\n <p page-description>${oauth2Client.description || ''}</p>\n </div>\n\n <div icon>\n <img src=${oauth2Client.icon}>\n </div>\n\n <form>\n <div fieldset-container>\n <fieldset>\n <legend>oauth2 client</legend>\n <div field-2column>\n <div field grid-span>\n <label for='name'>name</label>\n <input type='text' id=\"name\" name=\"name\" .value=${oauth2Client.name || ''}>\n </div>\n\n <div field grid-span>\n <label for='description'>description</label>\n <input type='text' id=\"description\" name=\"description\" .value=${oauth2Client.description || ''}>\n </div>\n\n <div field grid-span>\n <label for='icon'>icon</label>\n <input type='text' id=\"icon\" name=\"icon\" \n @change=${e => (this._icon = e.target.value)} \n .value=${oauth2Client.icon || ''}\n >\n </div>\n </div>\n </fieldset>\n </div>\n\n <div fieldset-container>\n <fieldset>\n <legend>authorization</legend>\n <div field-2column>\n <div field grid-span>\n <label for='grant-type'>grant type\n <ox-help-icon topic='/oauth2-client/grant-type'></ox-help-icon>\n </label>\n <select type='text' id=\"grant-type\" name=\"grantType\" .value=${oauth2Client.grantType || 'code'} \n @change=${e => (this._grantType = e.target.value)}>\n <option></option>\n <option value='code'>Authorization Code Grant</option>\n <option value='jwt'>JWT As Authorization Grant</option>\n <option value='owner'>Resource Owner Password Credentials Grant</option>\n <option value='credentials'>Client Credentials Grant</option>\n </select>\n </div>\n\n <div field grid-span>\n <label for='auth-url'>auth url</label>\n <input type='text' id=\"auth-url\" name=\"authUrl\" .value=${oauth2Client.authUrl || ''}>\n <div input-hint>The endpoint for authorization server. This is used to get the authorization code.</div>\n </div>\n\n <div field grid-span>\n <label for='access-token-url'>access token url</label>\n <input type='text' id=\"access-token-url\" name=\"accessTokenUrl\" .value=${ oauth2Client.accessTokenUrl || ''\n }>\n <div input-hint>The endpoint for authentication server. This is used to exchange the authorization code for an access token.</div>\n </div>\n\n <div field grid-span>\n <label for='callback-url'>callback url</label>\n <input type='text' id=\"callback-url\" name=\"callbackUrl\" .value=${oauth2Client.callbackUrl || ''}>\n <div input-hint>This is the callback url that you will be redirected to, after your application is authorized.\n This is used to extract the authorization code or access token.\n Normally, this callback url should match the one you use during the application registration process.\n If you leave this field empty, default callback url(${ location.origin\n }/oauth2-client/callback</label>) will be used.</div>\n </div>\n \n <div field grid-span>\n <label for='client-id'>client id</label>\n <input type='text' id=\"client-id\" name=\"clientId\" .value=${oauth2Client.clientId || ''}>\n <div input-hint>The client identifier issued to the client during the application registration process.</div>\n </div>\n\n <div field grid-span>\n <label for='client-secret'>client secret</label>\n <input type='text' id=\"client-secret\" name=\"clientSecret\" .value=${oauth2Client.clientSecret || ''}>\n <div input-hint>The client secret issued to the client during the application registration process.</div>\n </div>\n\n ${ this._grantType == 'owner'\n ? html`\n <div field grid-span>\n <label for=\"username\">user name</label>\n <input type=\"text\" id=\"username\" name=\"username\" .value=${oauth2Client.username || ''} />\n </div>\n\n <div field grid-span>\n <label for=\"password\">password</label>\n <input type=\"password\" id=\"password\" name=\"password\" .value=${oauth2Client.password || ''} />\n </div>\n `\n : html``\n }\n\n ${ this._grantType == 'jwt'\n ? html`\n <div field grid-span>\n <label for=\"jwt-token\">jwt-token</label>\n <input type=\"text\" id=\"jwt-token\" name=\"jwtToken\" .value=${oauth2Client.jwtToken || ''} />\n <div input-hint>The JWT Bearer Token for JWT As Authorization Grant</div>\n </div>\n `\n : html``\n }\n\n <!-- code PKCE grant type not supported yet\n <div field grid-span>\n <label for='code-challenge-method'>code challenge method</label>\n <select type='text' id=\"code-challenge-method\" name=\"codeChallengeMethod\" .value=${ oauth2Client.codeChallengeMethod\n }>\n <option></option>\n <option>SHA-256</option>\n <option>Plain</option>\n </select>\n <div input-hint>Algorithm used for generating the code challenge</div>\n </div>\n\n <div field grid-span>\n <label for='code-verifier'>code verifier\n <ox-help-icon topic='/oauth2-client/code-verifier'></ox-help-icon>\n </label>\n <input type='text' id=\"code-verifier\" name=\"codeVerifier\" .value=${oauth2Client.codeVerifier || ''}>\n <div input-hint>A random, 43-128 character string used to connect the authorization request to the token request.\n Uses the following characters: [A-Z]/[a-z]/[0-9]/\"-\"/\".\"/\"_\"/\"~\".</div>\n </div>\n -->\n \n <div field grid-span>\n <label for='scopes'>scopes</label>\n <input type='text' id=\"scopes\" name=\"scopes\" .value=${oauth2Client.scopes || ''}>\n <div input-hint>The scopes of the access request. It may have multiple space-delimited values.</div>\n </div>\n </div>\n </fieldset>\n </div>\n\n <div fieldset-container>\n <fieldset>\n <div field grid-span>\n <label for='token-type'>token type</label>\n <input type='text' id=\"token-type\" .value=${oauth2Client.tokenType || ''} readonly>\n <div input-hint>Added to the authorization header before the access token.</div>\n </div>\n\n <legend>access token</legend>\n <div field-2column>\n <div field grid-span>\n <label for=\"access-token\">access token</label>\n <input id=\"access-token\" type=\"text\" .value=${oauth2Client.accessToken || ''} readonly />\n <button button-in-field clipboard-copy @click=${e => e.preventDefault()}>copy</button>\n ${ oauth2Client.expires\n ? html`<div input-hint>\n expired in ${new Date(Number(oauth2Client.expires))} :\n ${asyncReplace(this.expTimer(oauth2Client.expires))}\n </div>`\n : html``\n }\n </div>\n\n <div field grid-span>\n <label for=\"refresh-token\">refresh token</label>\n <input id=\"refresh-token\" type=\"text\" .value=${oauth2Client.refreshToken || ''} readonly />\n <button button-in-field clipboard-copy @click=${e => e.preventDefault()}>copy</button>\n </div>\n </div>\n </fieldset>\n </div>\n\n <button @click=${e => this.deleteOauth2Client(e)}>delete this app</button>\n <button @click=${async e => { e.preventDefault()\n await this.updateOauth2Client()\n await this.generateOauth2AccessToken()\n }}>get new access token</button>\n <button @click=${async e => { e.preventDefault()\n await this.updateOauth2Client()\n await this.refreshOauth2AccessToken()\n }} ?disabled=${!oauth2Client.refreshToken}>refresh access token</button>\n <input type=\"submit\" value=\"update\" @click=${async e => { e.preventDefault()\n await this.updateOauth2Client()\n }}>\n </form>\n `\n }\n\n updated(changes) { if (changes.has('oauth2Client')) { this._grantType = this.oauth2Client?.grantType\n }\n }\n\n firstUpdated() { this.clipboard = new Clipboard(this.copybuttons, { target: (trigger => trigger.parentElement.querySelector('input')) as any\n })\n }\n\n async pageUpdated(changes, lifecycle, before) { if (this.active) { await this.fetchOauth2Client()\n }\n }\n\n async *expTimer(exp) { const DAY = 24 * 60 * 60\n const HOUR = 60 * 60\n const MIN = 60\n\n while (this.active) { var remain = Math.floor((Number(exp) - Date.now()) / 1000)\n const days = Math.floor(remain / DAY)\n remain -= days * DAY\n const hours = Math.floor(remain / HOUR)\n remain -= hours * HOUR\n const mins = Math.floor(remain / MIN)\n const secs = remain - mins * MIN\n\n yield `${days} days ${hours} hours ${mins} mins ${secs} seconds remain`\n\n await sleep(1000)\n }\n }\n\n async fetchOauth2Client() { const response = await client.query({ query: gql`\n query($id: String!) { oauth2Client(id: $id) { ${OAUTH2CLIENT}\n }\n }\n `,\n variables: { id: this.lifecycle.resourceId\n }\n })\n\n this.oauth2Client = response.data.oauth2Client\n }\n\n async updateOauth2Client() { const formData = new FormData(this.form)\n\n const patch = Array.from(formData.entries()).reduce((patch, [key, value]) => { patch[key] = value\n return patch\n }, {})\n\n const id = this.lifecycle.resourceId\n\n const response = await client.mutate({ mutation: gql`\n mutation($id: String!, $patch: Oauth2ClientPatch!) { updateOauth2Client(id: $id, patch: $patch) { ${OAUTH2CLIENT}\n }\n }\n `,\n variables: { id,\n patch\n }\n })\n\n if (response.errors) { notify({ level: 'error',\n message: 'update oauth2 client fail'\n })\n } else { this.oauth2Client = response.data.updateOauth2Client\n }\n }\n\n async deleteOauth2Client(e) { e.preventDefault()\n\n const id = this.lifecycle.resourceId\n\n const response = await client.mutate({ mutation: gql`\n mutation ($id: String!) { deleteOauth2Client(id: $id)\n }\n `,\n variables: { id\n }\n })\n\n if (response.errors) { notify({ level: 'error',\n message: 'delete oauth2 client fail'\n })\n } else { navigate('oauth2-clients')\n }\n }\n\n async generateOauth2AccessToken() { const id = this.lifecycle.resourceId\n\n if (this.oauth2Client.grantType == 'code') { const response = await client.mutate({ mutation: gql`\n mutation ($id: String!) { getOauth2AuthUrl(id: $id)\n }\n `,\n variables: { id: this.lifecycle.resourceId\n }\n })\n\n if (!response.errors) { location.href = response.data.getOauth2AuthUrl\n } else { notify({ level: 'error',\n message: 'getting application access token fail'\n })\n }\n } else { const response = await client.mutate({ mutation: gql`\n mutation($id: String!) { getOauth2AccessToken(id: $id) { ${OAUTH2CLIENT}\n }\n }\n `,\n variables: { id: this.lifecycle.resourceId\n }\n })\n\n if (response.errors) { notify({ level: 'error',\n message: 'getting application access token fail'\n })\n } else { this.oauth2Client = response.data.getOauth2AccessToken\n notify({ level: 'info',\n message: 'got application access token successfully'\n })\n }\n }\n }\n\n async refreshOauth2AccessToken() { const id = this.lifecycle.resourceId\n\n const response = await client.mutate({ mutation: gql`\n mutation($id: String!) { refreshOauth2AccessToken(id: $id) { ${OAUTH2CLIENT}\n }\n }\n `,\n variables: { id: this.lifecycle.resourceId\n }\n })\n\n if (response.errors) { notify({ level: 'error',\n message: 'getting application access token fail'\n })\n } else { this.oauth2Client = response.data.refreshOauth2AccessToken\n notify({ level: 'info',\n message: 'got application access token successfully'\n })\n }\n }\n}\n"]}