A Framework independent javascript library that makes working with Oracle WebCenter (11g & 12c) REST API a breeze.It cannot get any simpler than this
Library encapsulates all the logic necessary for
- Authentication using
- Basic Auth
- OIT Trust token generated by WCSecurityUtility
- SSO
- Parse Link Model
- Discussions
- Lists
- People Connections
- Content Management (CMIS)
- Events
- Feedback
- Navigation
- Activity Stream
- Message Boards
Works with framework of your choice. KnockoutJS, Angular, React, React Native, NodeJS, jQuery just to name a few.
- Built with TypeScript.
- Distributed as NPM & Bower packages.
- CommonJS & Bundled distributions.
- Full Intellisense in Visual Code, WebStorm , Sublime Text etc.
- Type Definitions.
- Automatically handles utoken & Link Model parsing.
- Promise based.
CommonJS distribution that integrates well with Modern frameworks like Angular, React, Aurelia, VueJS, etc.
> npm install webcenterjs --save
Bundled distribution that integrates well with jQuery, KnockoutJS or plain old javascript.
> bower install webcenterjs --save
Install webcenterjs NPM module as shown above and use the following snippet.
// import module
import WebCenter from "webcenterjs";
import {WallMessageItem} from "webcenterjs"; // Required only for TypeScript, for type definitions.
/**
* Assuming Oracle WebCeter Installation is available at
* http(s)://wc-host-name:8888/. The following context roots will be available
* OOTB
*
* WebCenter : http(s)://wc-host-name:8888/webcenter
* Content : http(s)://wc-host-name:16200/cs
* REST API : http(s)://wc-host-name:8888/rest
*/
/**
* Set REST Base URL.
* Automatically defaults to [window.location.protocol, "//", window.location.host, "/rest"].join("") when running on browser.
*
* Defaults to "/rest" when running on NodeJS, React Native.
*
* It is recommended to set the REST Base URL
*/
WebCenter.Config.setRestBaseUrl("http(s)://wc-host-name:8888/rest");
/**OPTIONAL : Optionally set WC & CS Base URLs as shown below
* The WC & CS URLs will come into play only for Basic Authentication and not for SSO or OIT.
*/
WebCenter.Config.setWcBaseUrl("http(s)://wc-host-name:8888/webcenter");
WebCenter.Config.setCsBaseUrl("http(s)://wc-host-name:16200/cs");
/**OPTIONAL : Optionally set Usename & Password
* 1. When username & password are provided, Basic Authentication is used.
* 2. WebCenter.Auth.setOIT("<OIT_TOKEN>") can be used to work with OIT token.
* 3. When neither is provided, SSO is assumed.
*/
WebCenter.Auth.setUserName(username);
WebCenter.Auth.setPassword(password);
WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then((messageItem: WallMessageItem) => {
console.log("------ Congrats on your Post ---------", messageItem.id);
}, (error: any) => {
console.error(error);
});
In the above example, when postMessage is done, the following happens
- GET request to http(s)://wc-host-name:8888/rest/resourceIndex with Basic Auth.
- Extract uToken.
- Parse Link Model.
- postMessage using the uToken
Explicit login can be performed using the following snippet, if needed
WebCenter.Auth.login().then((resourceIndex: ResourceIndex) => {
console.log(resourceIndex);
// ... Do something elese
// for ex.
/**
WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then((messageItem: WallMessageItem) => {
console.log("------ Congrats on your Post ---------", messageItem.id);
}, (error: any) => {
console.error(error);
});
*/
},(error:Error) => {
console.error(error);
});
<script src="bower_components/webcenterjs/dist/lib/webcenter.bundle.min.js"></script>
With the above script a global object WebCenter is registered on the window.
/**
* Assuming Oracle WebCeter Installation is available at
* http(s)://wc-host-name:8888/. The following context roots will be available
* OOTB
*
* WebCenter : http(s)://wc-host-name:8888/webcenter
* Content : http(s)://wc-host-name:16200/cs
* REST API : http(s)://wc-host-name:8888/rest
*/
/**
* Set REST Base URL.
* Automatically defaults to [window.location.protocol, "//", window.location.host, "/rest"].join("") when running on browser.
*
* Defaults to "/rest" when running on NodeJS, React Native.
*
* It is recommended to set the REST Base URL
*/
WebCenter.Config.setRestBaseUrl("http(s)://wc-host-name:8888/rest");
/**OPTIONAL : Optionally set WC & CS Base URLs as shown below
* The WC & CS URLs will come into play only for Basic Authentication and not for SSO or OIT.
*/
WebCenter.Config.setWcBaseUrl("http(s)://wc-host-name:8888/webcenter");
WebCenter.Config.setCsBaseUrl("http(s)://wc-host-name:16200/cs");
/**OPTIONAL : Optionally set Usename & Password
* 1. When username & password are provided, Basic Authentication is used.
* 2. WebCenter.Auth.setOIT("<OIT_TOKEN>") can be used to work with OIT token.
* 3. When neither is provided, SSO is assumed.
*/
WebCenter.Auth.setUserName(username);
WebCenter.Auth.setPassword(password);
WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then(function(messageItem){
console.log("------ Congrats on your Post ---------", messageItem.id);
}, function(error){
console.error(error);
});
Explicit login can be performed using the following snippet, if needed
WebCenter.Auth.login().then(function(resourceIndex){
console.log(resourceIndex);
// ... Do something elese
// for ex.
/**
WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then(function(messageItem){
console.log("------ Congrats on your Post ---------", messageItem.id);
}, function(error) => {
console.error(error);
});
*/
},function(error){
console.error(error);
});
Make sure Oracle WebCenter Portal is configured as per instructions at Configuring REST APIs
Oracle WebCenter REST API responses confirm to HATEOAS Standard.
WebCenterJS automatically parses the link model and enriches the response as shown below
In the above screenshot, note that the response wcResIdx is enriched and contains several methods that can be called direclty (getInvitations in this case).