Bladeren bron

Enhanced docs for the tokenUrl config.

Maciej Bukowski 7 jaren geleden
bovenliggende
commit
eb96cfd4a5
1 gewijzigde bestanden met toevoegingen van 48 en 3 verwijderingen
  1. 48 3
      packages/ckeditor5-cloud-services/src/cloudservices.js

+ 48 - 3
packages/ckeditor5-cloud-services/src/cloudservices.js

@@ -35,7 +35,7 @@ export default class CloudServices extends Plugin {
 		 * The authentication token URL for CKEditor Cloud Services.
 		 *
 		 * @readonly
-		 * @member {String|undefined} #tokenUrl
+		 * @member {String|Function|undefined} #tokenUrl
 		 */
 
 		/**
@@ -94,17 +94,62 @@ CloudServices.Token = Token;
  */
 
 /**
- * The URL to the security token endpoint in your application. The role of this endpoint is to securely authorize the
+ * A token URL or a token request function.
+ *
+ * As a string it should be a URL to the security token endpoint in your application. The role of this endpoint is to securely authorize the
  * end users of your application to use [CKEditor Cloud Services](https://ckeditor.com/ckeditor-cloud-services), only
  * if they should have access e.g. to upload files with Easy Image or to access the Collaboraation service.
  *
+ *		ClassicEditor
+ *			.create( document.querySelector( '#editor' ), {
+ *				cloudServices: {
+ *					tokenUrl: 'https://example.com/cs-token-endpoint',
+ *					...
+ *				}
+ *			} )
+ *			.then( ... )
+ *			.catch( ... );
+ *
+ * As a function it should provide a promise to the token value, so you can highly customize the token and provide your token URL endpoint.
+ * By using that approach you can set your own headers to the request.
+ *
+ * 		ClassicEditor
+ *			.create( document.querySelector( '#editor' ), {
+ *				cloudServices: {
+ *					tokenUrl: () => new Promise( ( resolve, reject ) => {
+ *						const xhr = new XMLHttpRequest();
+ *
+ *						xhr.open( 'GET', 'https://example.com/cs-token-endpoint' );
+ *
+ *						xhr.addEventListener( 'load', () => {
+ *							const statusCode = xhr.status;
+ *							const xhrResponse = xhr.response;
+ *
+ *							if ( statusCode < 200 || statusCode > 299 ) {
+ *								return reject( new Error( 'Cannot download new token!' ) );
+ *							}
+ *
+ *							return resolve( xhrResponse );
+ *						} );
+ *
+ *						xhr.addEventListener( 'error', () => reject( new Error( 'Network Error' ) ) );
+ *						xhr.addEventListener( 'abort', () => reject( new Error( 'Abort' ) ) );
+ *
+ *						xhr.setRequestHeader( customHeader, customValue );
+ *
+ *						xhr.send();
+ *					} ),
+ *					...
+ *				}
+ *			} )
+ *
  * You can find more information about token endpoints in the
  * {@glink @cs guides/quick-start#create-token-endpoint Cloud Services - Quick start}
  * and {@glink @cs guides/token-endpoints/tokenendpoint Cloud Services - Creating token endpoint} documentation.
  *
  * Without a properly working token endpoint (token URL) CKEditor plugins will not be able to connect to CKEditor Cloud Services.
  *
- * @member {String} module:cloud-services/cloudservices~CloudServicesConfig#tokenUrl
+ * @member {String|Function} module:cloud-services/cloudservices~CloudServicesConfig#tokenUrl
  */
 
 /**