| 
1 |  | -import { LitElement, html, css } from 'lit-element';  | 
2 |  | -import { AmfHelperMixin } from '@api-components/amf-helper-mixin/amf-helper-mixin.js';  | 
3 |  | -/**  | 
4 |  | - * `api-oauth1-settings-document`  | 
5 |  | - *  | 
6 |  | - * Documentation view for AMF OAuth2 security settings.  | 
7 |  | - *  | 
8 |  | - * Settings can be passed by setting the `settings` property to AMF's  | 
9 |  | - * settings property of Security Scheme.  | 
10 |  | - *  | 
11 |  | - * ```html  | 
12 |  | - * <api-oauth1-settings-document  | 
13 |  | - *  amf-model="{...}"  | 
14 |  | - *  settings="{...}"></api-oauth1-settings-document>  | 
15 |  | - * ```  | 
16 |  | - *  | 
17 |  | - * It is also possible to set corresponding properties directly.  | 
18 |  | - *  | 
19 |  | - * ```html  | 
20 |  | - * <api-oauth1-settings-document  | 
21 |  | - *  amf-model="{...}"  | 
22 |  | - *  request-token-uri="https://..."  | 
23 |  | - *  authorization-uri="https://..."  | 
24 |  | - *  signatures='["RSA-SHA1"]'></api-oauth1-settings-document>  | 
25 |  | - * ```  | 
26 |  | - *  | 
27 |  | - * ## Styling  | 
28 |  | - *  | 
29 |  | - * `<api-oauth1-settings-document>` provides the following custom properties and mixins for styling:  | 
30 |  | - *  | 
31 |  | - * Custom property | Description | Default  | 
32 |  | - * ----------------|-------------|----------  | 
33 |  | - * `--api-oauth1-settings-document` | Mixin applied to this elment | `{}`  | 
34 |  | - *  | 
35 |  | - * @customElement  | 
36 |  | - * @polymer  | 
37 |  | - * @demo demo/index.html  | 
38 |  | - * @memberof ApiElements  | 
39 |  | - * @appliesMixin AmfHelperMixin  | 
40 |  | - */  | 
41 |  | -class ApiOauth1SettingsDocument extends AmfHelperMixin(LitElement) {  | 
42 |  | -  get styles() {  | 
43 |  | -    return css`:host {  | 
44 |  | -      display: block;  | 
45 |  | -    }  | 
46 |  | -
  | 
47 |  | -    h4 {  | 
48 |  | -      font-size: var(--arc-font-subhead-font-size);  | 
49 |  | -      font-weight: var(--arc-font-subhead-font-weight);  | 
50 |  | -      line-height: var(--arc-font-subhead-line-height);  | 
51 |  | -    }  | 
52 |  | -
  | 
53 |  | -    .settings-value {  | 
54 |  | -      background: var(--code-background-color, #f5f2f0);  | 
55 |  | -      display: block;  | 
56 |  | -      padding: 1em;  | 
57 |  | -      margin: .5em 0;  | 
58 |  | -    }`;  | 
59 |  | -  }  | 
60 |  | - | 
61 |  | -  render() {  | 
62 |  | -    const { requestTokenUri, authorizationUri, tokenCredentialsUri, signatures } = this;  | 
63 |  | -    return html`<style>${this.styles}</style>  | 
64 |  | -    ${requestTokenUri ? html`<h4 data-type="request-token-uri">Request token URI</h4>  | 
65 |  | -    <code class="settings-value">${requestTokenUri}</code>` : undefined}  | 
66 |  | -
  | 
67 |  | -    ${authorizationUri ? html`<h4 data-type="authorization-uri">Authorization URI</h4>  | 
68 |  | -    <code class="settings-value">${authorizationUri}</code>` : undefined}  | 
69 |  | -
  | 
70 |  | -    ${tokenCredentialsUri ? html`<h4 data-type="token-credentials-uri">Token credentials URI</h4>  | 
71 |  | -    <code class="settings-value">${tokenCredentialsUri}</code>` : undefined}  | 
72 |  | -
  | 
73 |  | -    ${signatures && signatures.length ? html`  | 
74 |  | -      <h4 data-type="signatures">Supported signatures</h4>  | 
75 |  | -      <ul>  | 
76 |  | -      ${signatures.map((item) => html`<li>${item}</li>`)}  | 
77 |  | -      </ul>  | 
78 |  | -      ` : undefined}`;  | 
79 |  | -  }  | 
80 |  | - | 
81 |  | -  static get properties() {  | 
82 |  | -    return {  | 
83 |  | -      /**  | 
84 |  | -       * OAuth1 settings scheme of AMF.  | 
85 |  | -       * When this property changes it resets other properties.  | 
86 |  | -       * @type {Object}  | 
87 |  | -       */  | 
88 |  | -      settings: { type: Object },  | 
89 |  | -      /**  | 
90 |  | -       * The request token URI from the settings model.  | 
91 |  | -       * Automatically set when `settings` property change.  | 
92 |  | -       */  | 
93 |  | -      requestTokenUri: { type: String },  | 
94 |  | -      /**  | 
95 |  | -       * The authorization endpoint URI.  | 
96 |  | -       * Automatically set when `settings` property change.  | 
97 |  | -       */  | 
98 |  | -      authorizationUri: { type: String },  | 
99 |  | -      /**  | 
100 |  | -       * Token credentials endpoint URI.  | 
101 |  | -       * Automatically set when `settings` property change.  | 
102 |  | -       */  | 
103 |  | -      tokenCredentialsUri: { type: String },  | 
104 |  | -      /**  | 
105 |  | -       * List of signatures used by this authorization server.  | 
106 |  | -       * Automatically set when `settings` property change.  | 
107 |  | -       * @type {Array<String>}  | 
108 |  | -       */  | 
109 |  | -      signatures: { type: Array }  | 
110 |  | -    };  | 
111 |  | -  }  | 
112 |  | - | 
113 |  | -  get settings() {  | 
114 |  | -    return this._settings;  | 
115 |  | -  }  | 
116 |  | - | 
117 |  | -  set settings(value) {  | 
118 |  | -    const old = this._settings;  | 
119 |  | -    /* istanbul ignore if */  | 
120 |  | -    if (old === value) {  | 
121 |  | -      return;  | 
122 |  | -    }  | 
123 |  | -    this._settings = value;  | 
124 |  | -    this._settingsChanged(value);  | 
125 |  | -  }  | 
126 |  | - | 
127 |  | -  /**  | 
128 |  | -   * Called automatically when `settings` property change (whole object,  | 
129 |  | -   * not sub property).  | 
130 |  | -   * Sets values of all other properties to the one found in the AMF.  | 
131 |  | -   *  | 
132 |  | -   * @param {Object} settings AMF settings to process.  | 
133 |  | -   */  | 
134 |  | -  _settingsChanged(settings) {  | 
135 |  | -    const requestTokenUri = this._computeRequestTokenUri(settings);  | 
136 |  | -    const authorizationUri = this._computeAuthorizationUri(settings);  | 
137 |  | -    const tokenCredentialsUri = this._computeTokenCredentialsUri(settings);  | 
138 |  | -    const signatures = this._computeSignatures(settings);  | 
139 |  | - | 
140 |  | -    this.requestTokenUri = requestTokenUri;  | 
141 |  | -    this.authorizationUri = authorizationUri;  | 
142 |  | -    this.tokenCredentialsUri = tokenCredentialsUri;  | 
143 |  | -    this.signatures = signatures;  | 
144 |  | -  }  | 
145 |  | -  /**  | 
146 |  | -   * If passed argument is an array it returns first object from it. Otherwise  | 
147 |  | -   * it returns the object.  | 
148 |  | -   * @param {any} result  | 
149 |  | -   * @return {any}  | 
150 |  | -   */  | 
151 |  | -  _deArray(result) {  | 
152 |  | -    if (result instanceof Array) {  | 
153 |  | -      result = result[0];  | 
154 |  | -    }  | 
155 |  | -    return result;  | 
156 |  | -  }  | 
157 |  | -  /**  | 
158 |  | -   * Computes value of request token endpoint URI.  | 
159 |  | -   * @param {Object} settings AMF settings to process.  | 
160 |  | -   * @return {String|undefined} Request token URI value  | 
161 |  | -   */  | 
162 |  | -  _computeRequestTokenUri(settings) {  | 
163 |  | -    const result = this._getValue(settings, this.ns.raml.vocabularies.security + 'requestTokenUri');  | 
164 |  | -    return this._deArray(result);  | 
165 |  | -  }  | 
166 |  | -  /**  | 
167 |  | -   * Computes value of authorization endpoint URI.  | 
168 |  | -   * @param {Object} settings AMF settings to process.  | 
169 |  | -   * @return {String|undefined} Authorization URI value  | 
170 |  | -   */  | 
171 |  | -  _computeAuthorizationUri(settings) {  | 
172 |  | -    const result = this._getValue(settings, this.ns.raml.vocabularies.security + 'authorizationUri');  | 
173 |  | -    return this._deArray(result);  | 
174 |  | -  }  | 
175 |  | -  /**  | 
176 |  | -   * Computes value of token credentials endpoint URI.  | 
177 |  | -   * @param {Object} settings AMF settings to process.  | 
178 |  | -   * @return {String|undefined} Token credentials URI value  | 
179 |  | -   */  | 
180 |  | -  _computeTokenCredentialsUri(settings) {  | 
181 |  | -    const result = this._getValue(settings, this.ns.raml.vocabularies.security + 'tokenCredentialsUri');  | 
182 |  | -    return this._deArray(result);  | 
183 |  | -  }  | 
184 |  | -  /**  | 
185 |  | -   * Computes value of OAuth1 signatures.  | 
186 |  | -   * @param {Object} settings AMF settings to process.  | 
187 |  | -   * @return {Array<String>|undefined} List of signatures.  | 
188 |  | -   */  | 
189 |  | -  _computeSignatures(settings) {  | 
190 |  | -    return this._getValueArray(settings, this.ns.raml.vocabularies.security + 'signature');  | 
191 |  | -  }  | 
192 |  | -}  | 
 | 1 | +import { ApiOauth1SettingsDocument } from './src/ApiOauth1SettingsDocument.js';  | 
193 | 2 | window.customElements.define('api-oauth1-settings-document', ApiOauth1SettingsDocument);  | 
0 commit comments