AppsOauth20Details.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import format from 'date-fns/format';
  17. import { Apps } from './Apps';
  18. export class AppsOauth20Details extends Apps {
  19. clientId!: String;
  20. clientSecret!: String;
  21. scope!: String;
  22. resourceIds!: String;
  23. authorizedGrantTypes!: String;
  24. registeredRedirectUris!: String;
  25. authorities!: String;
  26. accessTokenValiditySeconds!: String;
  27. refreshTokenValiditySeconds!: String;
  28. approvalPrompt!: String;
  29. // for OpenID Connect
  30. issuer!: String;
  31. audience!: String;
  32. algorithm!: String;
  33. algorithmKey!: String;
  34. encryptionMethod!: String;
  35. signature!: String;
  36. signatureKey!: String;
  37. subject!: String;
  38. userInfoResponse!: String;
  39. pkce!: String;
  40. select_authorizedGrantTypes!: string[];
  41. select_scope!: string[];
  42. constructor() {
  43. super();
  44. this.select_authorizedGrantTypes = ['authorization_code'];
  45. this.select_scope = ['read'];
  46. this.pkce = 'no';
  47. this.approvalPrompt = 'auto';
  48. }
  49. override init(data: any): void {
  50. Object.assign(this, data);
  51. super.init(data);
  52. if (this.status == 1) {
  53. this.switch_status = true;
  54. }
  55. if (this.approvalPrompt == '') {
  56. }
  57. this.select_scope = [''];
  58. let scopeArray: String[] = `${this.scope},`.split(',');
  59. for (let i = 0; i < scopeArray.length; i++) {
  60. this.select_scope.push(`${scopeArray[i]}`);
  61. }
  62. this.select_authorizedGrantTypes = [''];
  63. let authorizedGrantTypesArray = `${this.authorizedGrantTypes},`.split(',');
  64. for (let i = 0; i < authorizedGrantTypesArray.length; i++) {
  65. this.select_authorizedGrantTypes.push(authorizedGrantTypesArray[i]);
  66. }
  67. if (this.pkce == null || this.pkce == '') {
  68. this.pkce = 'no';
  69. }
  70. this.pkce = this.pkce.toLowerCase();
  71. }
  72. override trans(): void {
  73. if (this.switch_status) {
  74. this.status = 1;
  75. } else {
  76. this.status = 0;
  77. }
  78. this.scope = '';
  79. for (let i = 0; i < this.select_scope.length; i++) {
  80. if (this.select_scope[i] != '') {
  81. if (this.scope === '') {
  82. this.scope = this.select_scope[i];
  83. } else {
  84. this.scope = `${this.scope},${this.select_scope[i]}`;
  85. }
  86. }
  87. }
  88. this.authorizedGrantTypes = '';
  89. let n = 0;
  90. for (let i = 0; i < this.select_authorizedGrantTypes.length; i++) {
  91. if (this.select_authorizedGrantTypes[i] != '') {
  92. if (this.authorizedGrantTypes === '') {
  93. this.authorizedGrantTypes = this.select_authorizedGrantTypes[i];
  94. } else {
  95. this.authorizedGrantTypes = `${this.authorizedGrantTypes},${this.select_authorizedGrantTypes[i]}`;
  96. }
  97. }
  98. }
  99. }
  100. }